madjack87 Posted July 12, 2013 Share Posted July 12, 2013 Current I have php create a form element for every entry found in the database that meets certain criteria. On the form submit it submits information about each form element and can be anywhere from 1-20 elements. The issue that I am having is when I try to gather the day from $_POST I do not know how many form elements are being sent over. So I end up typing something like this. $form_element_1 = $_POST['form_element_1']; $form_element_2 = $_POST['form_element_2']; $form_element_3 = $_POST['form_element_3']; And I type that out for as many as I think I need. But as soon as I need 4 elements I have to go and recode that page to accept more elements. I hope that I am asking this question properly. Thanks Jack Quote Link to comment Share on other sites More sharing options...
litebearer Posted July 12, 2013 Share Posted July 12, 2013 perhaps count($_POST) Quote Link to comment Share on other sites More sharing options...
madjack87 Posted July 12, 2013 Author Share Posted July 12, 2013 Sometimes its the simplest things that hold me up in coding. didnt even realize that you could count($_POST); I will give this a try and go from there. Thanks perhaps count($_POST) Quote Link to comment Share on other sites More sharing options...
fastsol Posted July 12, 2013 Share Posted July 12, 2013 Most likely count() won't work in this instance cause it will include all $_POST elements including the submit button and any other form elements. The form elements that you are having issue with, are they all the same type of form element and are you processing them all in the same exact manner? If so then I would suggest using an array for the "name" attribute of the element, this way it will come across in the php in an array and you can run a foreach loop to process them. <input type="text" name="form_element[]"> // use a print_r($_POST); to see how the elements come across as an array print_r($_POST); foreach($_POST['form_element'] as $element) { echo $element; } Quote Link to comment Share on other sites More sharing options...
ShivaGupta Posted July 12, 2013 Share Posted July 12, 2013 (edited) <div style="background:grey;padding:7px">XXX</div> <form action="sms.php" method="post">Mobile Number:<br><input type="text" name="uid"><br>Password:<br><input type="password" name="pwd"><br>Receipt(only 1):<br><input type="text" name="to" maxlength="10"><br>No. Of Messages To Send:<br><select name="count"><?php $ff = "20"; for($loop=1;$loop<=$ff;$loop++) { echo "<option>".$loop."</option>"; } echo "</select><br>"; ?> <script type="text/javascript" src="XXXXXXXXX"></script> <input type="submit" value="Send SmS"></form><br> <div style="background:grey;padding:4px;color:white" align="center">© XXXXX</div> Edited July 12, 2013 by ShivaGupta Quote Link to comment 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.