Here is my HTML code:
<form name="candidates" action="candidate_thankyou.php" method="post">
<div class="wrap">
<div class="position"> President: <br> </div>
<input type="text" name="president"> <br>
<input type="text" name="president"> <br>
<input type="text" name="president"> <br>
</div>
<div class="wrap">
<div class="position"> Vice President: <br> </div>
<input type="text" name="vp"> <br>
<input type="text" name="vp"> <br>
<input type="text" name="vp"> <br>
</div> ...etc
<input id="submit" type="submit" value="Submit">
</form>
However, when I call var_dump($_POST) in my php file, I only get the last text box value for each input name (eg "president" or "vp"). If I only use the first 2 text boxes, I get an empty string. How can I get all three values from the form?
Field name must be either unique (president1
, president2
, etc.) or an array president[]
.
Further handling depends on which method you choose. Second method is well described in HTML form input tag name element array with JavaScript
Form fields are identified by their name. You're overriding the fields president
/vp
every time, that's why you only get the last field's values. You can send it as an array like this:
<input type="text" name="president[]">
<input type="text" name="president[]">
..
You should have seperate names for each input or add [] to the end of the names to add them to an array. Ie
name="vp[]"