0

Hello.

I have a quick question here. I have a html document with a very long form. Each element in the form has an label. The action of the form is

<FORM action="Bestallningsformular.php" method="get">

What I now want to do in the php document is to fetch the value and the label and print it in the php document. I can get the value but dont know how to get the lable.

Any help would be nice.

2
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by meazza
0

You can not get labels after form submission.
You can create hidden type field and value can be same as label, then when form submitted you can get hidden field value for labeling.

0

Does the hidden types need a unique name? Cause I have tried something similar with the the name and value where I give the same name as label but this does not work since "name" needs to have unique names and i have some repeating label namnes.

And how would I get these hidden types in my php? I am kind of newbish. Atm I do

foreach($_GET as $name => $value) 
  		{ 
  			echo $name . ':  ' . $value."</br>"; 
  		}
0

Try this code, you will understand how to use hidden field.

<?
	if(isset($_POST['save']))
	{
		echo 'Form Values:<br />';
		echo '<br />Name Label: '.$_POST['name_label'];
		echo '<br />Name Value: '.$_POST['name'];
		echo '<br />Email Label: '.$_POST['email_label'];
		echo '<br />Email Value: '.$_POST['email'];
		exit;
	}
?>
<form id="form1" name="form1" method="post" action="">
<table width="500" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td>Your Name<input type="hidden" name="name_label" value="Your Name" /></td>
    <td>
      <label>
        <input type="text" name="name" id="name" />
        </label>
   
    </td>
  </tr>
  <tr>
    <td>Your Email<input type="hidden" name="email_label" value="Your Email" /></td>
    <td><input type="text" name="email" id="email" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="save" id="button" value="Save" /></td>
  </tr>
</table> 
</form>
0

Yepp got it thank you very much. Now I have another question :).

My php code looks like this:

<?php

		$counter = 0;
		$counter2 = 0;
		echo "<TABLE>";
		foreach($_POST as $name => $value) 
  		{ 	
	  		if($counter == 0)
	  		{
  				echo $value.':  ';
  				$counter = 1; 
			}
			else
			{
				echo $value."</br>";
				$counter = 0;
			}
			$counter2 = $counter2 + 1;
			if($counter2 == 18)
			{
				echo "<h3 class=\"c8 c1\"><span class=\"c4\">Bolagsuppgifter</span></h3>";
			}
			if($counter2 == 44)
			{
				echo "<p class=\"c1 c3\"><span class=\"c0\"></span></p>";
				echo "<hr style=\"page-break-before:always;display:none;\"<p class=<\"c1\"><span class=\"c4\">Styrelseledam&ouml;ter</span><span class=\"c0\"> (Ange uppgifter enligt nedan f&ouml;r varje ledamot)</span></p>";
			}
			if($counter2 == 60)
			{
				echo "<p class=\"c1 c3\"><span class=\"c0\"></span></p>";
				echo "<p class=\"c1\"><span class=\"c4\">Styrelsesuppleanter</span><span class=\"c0\"> (Ange uppgifter enligt nedan f&ouml;r varje suppleant)</span></p>";
			}
			if($counter2 == 76)
			{
				echo "<p class=\"c1 c3\"><span class=\"c0\"></span></p>";
				echo "<p class=\"c1\"><span class=\"c4\">&Ouml;vriga aktie&auml;gare</span><span class=\"c0\"> (tex. F&ouml;retag eller personer som inte &auml;r ledamot eller suppleant)</span></p>";

			}
			if($counter2 == 92)
			{
				echo "<p class=\"c1 c3\"><span class=\"c0\"></span></p>";
				echo "<h3 class=<\"c8 c1\"><span class=\"c4\">VD som inte &auml;r ledamot eller suppleant.</span></h3>";
			}
			if($counter2 == 104)
			{
				echo "<h3 class=\"c1 c8\"><span class=\"c4\">S&auml;rskild firmatecknare </span><span class=\"c0\">(Firmatecknare som inte &auml;r ledamot, suppleant eller VD)</span></h3>";
			}
			if($counter2 == 116)
			{
				echo "<p class=\"c1 c3\"><span class=\"c0\"></span></p>";
				echo "<hr style=\"page-break-before:always;display:none;\"><p class=\"c1\"><span class=\"c4\">Revisorer och revisorssuppleanter </span><span class=\"c12\"></span></p><p class=\"c1\"><span class=\"c0\">(Ange uppgifter enligt nedan f&ouml;r varje revisor)</span></p>";
			}
  		}
?>
</br>
<SCRIPT LANGUAGE="JavaScript"> 
if (window.print) {
document.write('<form><input id= "btnPrint" type=button name=print value="Skriv ut" onClick="window.print()"></form>');
}
</script>

</body>
</html>

Where I have one option to the print the form info and now I want to create a email option. So the contect that is on the page is emailed. Whats the best way to do this?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.