View Full Version : dynamic number of input tags
usban
08-25-2002, 10:22 PM
I want to create a form with a dynamic number of input tags on it.
The problem comes when validating the form. In order to have access to the variables in the next page i need to name all the input tags whith diferent names, but what happens is that maybe it has 1 input or maybe it has 20 or more depending on the user.
I don't have any idea of have to deal with this problem.
Either pass the number as a hidden field
<input type="hidden" name="howmany" value="'.$numeric.'">
to access in the receiving page.
Otherwise - assuming you have a numeric part of the input(s) naming protocol... eg inp0 inp1 inp2 inp3 etc
for($s=0; $s<999; $s++) {
eval("\$testt = \$inp".$s.";");
if($testt == "") { // value of input is "" - so stop loop
$s=1000;
}
else {
// the real loop happens here - each input field is now called $testt and will be overwritten.
echo 'value of inp'.$s.' is --- '.$testt.'
';
}
}
You could build up an array using \$testt[] = .... if the values are needed later in the script. Note the if($testt=="") bit, that stops the script running all the way to 999 once it meets a field whose value is "" - ie, the first empty input field stops the loop.
I hope that helps anyway.
usban
08-26-2002, 10:05 AM
I've not tested yet, but i was thinking in the use of the function eval but i don't know how to use it. Thank You
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.