Jump to content

Help with PHP $_POST from a form


madjack87

Recommended Posts

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

Link to comment
Share on other sites

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; }
Link to comment
Share on other sites


<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 by ShivaGupta
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.