PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dourvas
Forum Commoner
Posts: 26 Joined: Fri Dec 05, 2008 7:21 am
Post
by dourvas » Sun Jan 18, 2009 4:37 am
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??????
it2051229
Forum Contributor
Posts: 312 Joined: Tue Dec 25, 2007 8:34 pm
Post
by it2051229 » Sun Jan 18, 2009 5:43 am
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
dourvas
Forum Commoner
Posts: 26 Joined: Fri Dec 05, 2008 7:21 am
Post
by dourvas » Sun Jan 18, 2009 7:46 am
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
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Sun Jan 18, 2009 11:37 am
please use php tags when posting code in the forums. I have added them for you this time.
dourvas
Forum Commoner
Posts: 26 Joined: Fri Dec 05, 2008 7:21 am
Post
by dourvas » Sun Jan 18, 2009 12:39 pm
sorry about that,
Anyone can help me????
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Sun Jan 18, 2009 1:04 pm
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[]">