Jump to content

How to loop the element of form


che_anj

Recommended Posts

Your question makes absolutely no sense. Also your HTML makes no sense.

All of your elements have the name "names".

That means that only one of their values is passed.

 

Perhaps your looking for an array.

 

//list of elements
$elements = array(1=>"username"
2=>"email",
3=>"name",
4=>"country"
);
//print the list
print "<table>";
foreach($elements as $key=>$value){
print "<tr>
<tr>
<b>" . ucfirst($value) . ": </b>
<input type=\"text\" name=\"" . $value . "\">
</td>
</tr>" 
}
print "</table>";

it would help if we knew what you were asking, exactly.  do you mean how do you loop through each element submitted in the POST request from a form?  if so, use foreach() on the $_POST array:

 

foreach ($_POST AS $name => $val)
{
  echo 'the element named '.$name.' was submitted with a value of '.$val.'<br />';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.