Storing form data using html & php

时间:2022-10-17 11:44:15

I've got a form with 50 questions. After the user has filled in the form, I want to take them to another page to first cancel / confirm that they are finished with the form. My question is if they select cancel, how do I put back all the fields that has been answered in the form?

我有一个包含50个问题的表格。在用户填写表单后,我想将他们带到另一个页面,首先取消/确认他们已完成表单。我的问题是,如果他们选择取消,我该如何放回表格中已回答的所有字段?

EDITED

EDITED

I've edited my question to show my code because I'm strugling:

我编辑了我的问题以显示我的代码,因为我很喜欢:

$sql1="SELECT * FROM ex_question WHERE test_name = '$tid' ORDER BY RAND()";
$result1=mysql_query($sql1);
echo "<form method='post' action='....'>";
while($row1 = mysql_fetch_array($result1))
{
    $test_name=$row1['test_name'];
    $q_nr=$row1['q_nr'];
    $q_type=$row1['q_type'];
    $question=$row1['question'];
    $option1=$row1['option1'];
    $option2=$row1['option2'];
    $option3=$row1['option3'];

echo "$question";

if ($q_type != 'mr') {
if($option1!="") {
echo "<input type='radio' name='question[$q_nr]' value='A'>$option1<BR>";
} else {
echo ''; }

if($option2!="") {
echo "<input type='radio' name='question[$q_nr]' value='B'>$option2<BR>";
} else {
echo ''; }

if($option3!="") {
echo "<input type='radio' name='question[$q_nr]' value='C'>$option3<BR>";
} else {
echo ''; }

} else { // else if not <> mr

if($option1!="") {
echo "<input type='checkbox' name='question[$q_nr][]' value='A'>$option1<BR>";
} else {
echo ''; } 
if($option2!="") {
echo "<input type='checkbox' name='question[$q_nr][]' value='B'>$option2<BR>";
} else {
echo ''; } 
if($option3!="") {
echo "<input type='checkbox' name='question[$q_nr][]' value='C'>$option3<BR>";
} else {
echo ''; } 
} //end else if q_type <> mr
echo "<BR>";
echo "<BR>";
echo "</p>";
} //end while row1
echo "<input type='submit' value='Finish'>";
echo "</form>";

4 个解决方案

#1


1  

Make the Cancel button a Submit and let it post back to the original questionnaire. In there, you can do like this:

将“取消”按钮设为“提交”,然后将其发回原始问卷。在那里,你可以这样做:

<input type="text" name="q1" value="<?=isset($_POST['q1']) ? $_POST['q1'] : '';?>" />

Or:

要么:

<input type="radio" name="q2" value="A" <?=isset($_POST['q2']) && $_POST['q2'] == 'A' ? 'checked="checked"' : '';?>" />
<input type="radio" name="q2" value="B" <?=isset($_POST['q2']) && $_POST['q2'] == 'B' ? 'checked="checked"' : '';?>" />

Same goes for option elements inside a select (selected="selected").

select(selected =“selected”)中的选项元素也是如此。

#2


1  

Pass the $_POST or $_GET array to the confirmation page, and if they hit cancel, pass the array back to the page, and fill in the elements.

将$ _POST或$ _GET数组传递给确认页面,如果它们点击取消,则将数组传递回页面,并填写元素。

#3


1  

The easiest solution would be adding:

最简单的解决方案是添加:

<INPUT type=button value="Cancel" onClick="history.back();">

When you go back, the form would still be there.

当你回去时,表格仍然存在。

#4


0  

You can just use $_REQUEST['Answer'] in value tag of form.

您可以在表单的值标记中使用$ _REQUEST ['Answer']。

#1


1  

Make the Cancel button a Submit and let it post back to the original questionnaire. In there, you can do like this:

将“取消”按钮设为“提交”,然后将其发回原始问卷。在那里,你可以这样做:

<input type="text" name="q1" value="<?=isset($_POST['q1']) ? $_POST['q1'] : '';?>" />

Or:

要么:

<input type="radio" name="q2" value="A" <?=isset($_POST['q2']) && $_POST['q2'] == 'A' ? 'checked="checked"' : '';?>" />
<input type="radio" name="q2" value="B" <?=isset($_POST['q2']) && $_POST['q2'] == 'B' ? 'checked="checked"' : '';?>" />

Same goes for option elements inside a select (selected="selected").

select(selected =“selected”)中的选项元素也是如此。

#2


1  

Pass the $_POST or $_GET array to the confirmation page, and if they hit cancel, pass the array back to the page, and fill in the elements.

将$ _POST或$ _GET数组传递给确认页面,如果它们点击取消,则将数组传递回页面,并填写元素。

#3


1  

The easiest solution would be adding:

最简单的解决方案是添加:

<INPUT type=button value="Cancel" onClick="history.back();">

When you go back, the form would still be there.

当你回去时,表格仍然存在。

#4


0  

You can just use $_REQUEST['Answer'] in value tag of form.

您可以在表单的值标记中使用$ _REQUEST ['Answer']。