I've been reading about arrays created by $_POST in PHP. I know that if I submit a form with the follow inputs ID, Name, Date I will end up with an array that includes $_POST = array('IDNo', 'Name', 'Date', 'State').
The point that I'm trying to get to is that I'll have multiple instances of IDNo, Name, Date, State submitted at the same time.
I'm fairly sure I can process and sanitize the data once it's been submitted, but I'm not sure how to get it into a multi row array.
<form method="post" action="test.php">
<input type="hidden" name="IDNo" />
<input type="text" name="Name" />
<input type="text" name="Date" />
<input type="radio" name="State1" />
<input type="hidden" name="IDNo" />
<input type="text" name="Name" />
<input type="text" name="Date" />
<input type="radio" name="State2" />
<input type="hidden" name="IDNo" />
<input type="text" name="Name" />
<input type="text" name="Date" />
<input type="radio" name="State3" />
<input type="submit" value="Test Me" />
</form>
One thing you'll notice is that the radio input has a unique name for each row. This is related to some jquery implemented on the page. I've seen IDNo[] and Name[] etc used as this would create the array within the $_POST array, but my unique input name on radio wouldn't work with this, as each radio input would be a different array
Would I be better to append the IDNo or a row number to each input name, or is there another way I can tackle this that I just haven't seen?
Perhaps by changing State1, to state[1] and changing IDNo, Name, Date to ID[1], Name[1], Date[1] within the HTML.
What's key for me is that I do it correctly without creating anything that is insecure.
$_POSTdata easily but if a radio input isn't checked, it won't appear in the data and your loop will be wrong. Using numbers can be better. Then loop through$_POSTand check existing inputs witharray_keysandstrpos.