Page 1 of 1

get data from a dynamic form

Posted: Sun Jan 18, 2009 4:37 am
by dourvas
hallo,

i ve created a dynamic form. A user can select The number of fields he d like to fill in (test creation)

Code: Select all

 
echo '<form method="post" action="createxml.php">';
for ($i =1; $i <=$number; $i+=1){ // THE $NUMBER CONTAINS VALUE -ok-
 
echo '<fieldset width ="20%">';
echo   '<legend class = "login">WRITE A QUESTION</legend>';
echo '   <blockquote align="center">';
echo 'QUESTION '.$i.' (DESCRIPTION):<br>';
echo '<textarea name="q".$i rows="3" cols="50"></textarea><br><br>';
echo 'ANSWEAR 1:<textarea name="q".$i."a1" rows="1" cols="50"></textarea><br>';
echo 'ANSWEAR 2:<textarea name="q".$i."a2" rows="1" cols="50"></textarea><br>';
echo 'ANSWEAR 3:<textarea name="q".$i."a3" rows="1" cols="50"></textarea><br>';
echo 'ANSWEAR 4:<textarea name="q".$i.a4" rows="1" cols="50"></textarea><br>';
 
echo '<input type="submit">';
echo '</form>';
 
Now in createxml.php i want to get the values in order to write them inside xml file. i have tried a lot but i can not do it. the last code i used which caused unfinishing loop with empty values was this

Code: Select all

 
echo "$number";//ok
for ($i =1; $i <=$number; $i+=1){
       $q.$i = $_POST['q'.$i];
       echo "$q.$i";// empty
       echo "<br>";
             
       $a.$i= $_POST["q".$i."a1"];
       $a.$i= $_POST["q".$i."a2"];
       $a.$i= $_POST["q".$i."a3"];
       $a.$i= $_POST["q".$i."a4"];
       
       echo "answear=".$_POST["q".$i."a4"];// empty
        echo "<br>";
 
    }
 
can u help me??????

Re: get data from a dynamic form

Posted: Sun Jan 18, 2009 5:43 am
by it2051229
you forgot the characters '[]' on the text area name
something like:

<textarea name="q".$i."a1[]" rows="1" cols="50"></textarea><br>
// including the others

Re: get data from a dynamic form

Posted: Sun Jan 18, 2009 7:46 am
by dourvas
sorry man but i can not understand what you r saying

could u be more specific???

my code now is

the form

Code: Select all

 
echo '<form method="post" action="createxml.php">';
for ($i =1; $i <=$number; $i+=1){
 
echo '<fieldset width ="20%">';
echo '<legend class = "login"></legend>';
echo ' <blockquote align="center">';
echo 'Questions '.$i.' (description):<br>';
echo '<textarea name="q' . $i . '" rows="3" cols="50"></textarea><br><br>';
echo 'answear 1:<textarea name="q' . $i . 'a1" rows="1" cols="50"></textarea><br>';
echo 'answear 2:<textarea name="q' . $i . 'a1" rows="1" cols="50"></textarea><br>';
echo 'answear 3:<textarea name="q' . $i . 'a1" rows="1" cols="50"></textarea><br>';
echo 'answear 4:<textarea name="q' . $i . 'a1" rows="1" cols="50"></textarea><br>';
echo ' </blockquote>';
echo '</fieldset>';
}
echo '<input type="submit">';
echo '</form>';
 
the createxml.php
 
for ($i =1; $i <=$number; $i+=1){
$temp="q' . $i . '";
$q[$i] = $_POST[$temp];
echo $q[$i];// empty
echo "<br>";
 
$qa1[$i]= $_POST["q' . $i . 'a1"];
$qa2[$i]= $_POST["q' . $i . 'a2"];
$qa3[$i]= $_POST["q' . $i . 'a3"];
$qa4[$i]= $_POST["q' . $i . 'a4"];
 
echo "answear=".$qa4[$i]; //empty
echo "<br>";
 
}
 
whats wrong??? the arrays r empty

Re: get data from a dynamic form

Posted: Sun Jan 18, 2009 11:37 am
by Burrito
please use php tags when posting code in the forums. I have added them for you this time.

Re: get data from a dynamic form

Posted: Sun Jan 18, 2009 12:39 pm
by dourvas
sorry about that,

Anyone can help me????

Re: get data from a dynamic form

Posted: Sun Jan 18, 2009 1:04 pm
by Burrito
I don't fully understand your question as it's not phrased very well.

If you're trying to set your form fields as arrays, then you need to do what the previous poster suggested

Code: Select all

 
<input type="checkbox" name="mycheck[]">