che_anj Posted August 16, 2007 Share Posted August 16, 2007 How to loop the elements of the form, include the Title.. example <tr><td>Name:</td><input type="text" name="names"></tr> <tr><td>Username:</td><input type="text" name="names"></tr> <tr><td>Email:</td><input type="text" name="names"></tr> tnx,... Quote Link to comment https://forums.phpfreaks.com/topic/65241-how-to-loop-the-element-of-form/ Share on other sites More sharing options...
che_anj Posted August 16, 2007 Author Share Posted August 16, 2007 hello anybody have an idea? Quote Link to comment https://forums.phpfreaks.com/topic/65241-how-to-loop-the-element-of-form/#findComment-325810 Share on other sites More sharing options...
lightningstrike Posted August 16, 2007 Share Posted August 16, 2007 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/65241-how-to-loop-the-element-of-form/#findComment-325813 Share on other sites More sharing options...
akitchin Posted August 16, 2007 Share Posted August 16, 2007 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 />'; } Quote Link to comment https://forums.phpfreaks.com/topic/65241-how-to-loop-the-element-of-form/#findComment-325816 Share on other sites More sharing options...
emehrkay Posted August 16, 2007 Share Posted August 16, 2007 your problem is that all of your form elements are named "names" meaning that there will only be one $_POST['names'] and its value will be the last element with that name. when you fix that, you'll be able to loop it as akitchin suggested Quote Link to comment https://forums.phpfreaks.com/topic/65241-how-to-loop-the-element-of-form/#findComment-325821 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.