Я очень новичок в программировании на PHP, это было всего лишь 3 дня с тех пор, как я начал, поэтому мне нужна ваша помощь. Я создаю форму, которая содержит 4 страницы. Когда пользователь нажимает кнопку «Назад», например, со страницы 2 на стр. 1, все данные, которые он ранее выбрал на стр. 1, должны присутствовать там, чтобы он не заполнял ее снова. Не могли бы вы помочь мне с этим, разместив код.Проблема с кнопкой НАЗАД
Вот пример кода
page1.php
<?php
session_start();
$session=session_id();
$_SESSION['session']=$session;
?>
<html>
<body>
<form action="oopssurvey.php" method="post">
Where do you work?<br/>
<Input type ="radio" name="location" value="USA" <?php if($_SESSION['location'] == 'USA') echo "checked='checked'" ?>/>In the United states<br/>
<Input type ="radio" name="location" value="India" <?php if($_SESSION['location'] == 'India') echo "checked='checked'" ?>/>Outside of the United states<br/>
<input name="Operation1" type="submit" value="saveandresume" />
<input name="Operation2" type="submit" value="next" />
</form>
</body>
</html>
page2.php
<?php
session_start();
if($_SESSION['session']==$session)
{
$location=$_SESSION['location'];
}
else
{
$_SESSION['location'] = $_POST['location'];
}
?>
<html>
<body>
<form action="oopssurvey.php" method="post">
In my work group, we are actively involved in making our work processes more effective and efficient (simpler, faster, etc.) using ACE.<br/>
<Input type ="radio" name="effective" value="Agree"/>Agree<br/>
<Input type ="radio" name="effective" value="Agreenordisagree"/>Neither Agree nor Disagree<br/>
<Input type ="radio" name="effective" value="disagree"/>Disagree<br/>
I have received the training I need to understand and implement ACE in my work group.<br/>
<Input type ="radio" name="training" value="Agree"/>Agree<br/>
<Input type ="radio" name="training" value="Agreenordisagree"/>Neither Agree nor Disagree<br/>
<Input type ="radio" name="training" value="disagree"/>Disagree<br/>
All employees at the company are treated fairly regardless of differences.<br/>
<Input type ="radio" name="treated" value="Agree"/>Agree<br/>
<Input type ="radio" name="treated" value="Agreenordisagree"/>Neither Agree nor Disagree<br/>
<Input type ="radio" name="treated" value="disagree"/>Disagree<br/>
Sufficient effort is made to get the opinions and thoughts of the people who work here.<br/>
<Input type ="radio" name="effort" value="Agree"/>Agree<br/>
<Input type ="radio" name="effort" value="Agreenordisagree"/>Neither Agree nor Disagree<br/>
<Input type ="radio" name="effort" value="disagree"/>Disagree<br/>
<input name="Operation3" type="submit" value="saveandresume" />
<input name="Operation4" type="submit" value="next" />
<input name="Operation5" type="submit" value="back" />
</form>
</body>
</html>
page3.php
// somecode //
Survey .php
<?php
session_start();
include 'classperson.php';
if($_POST['Operation1'])
{
$_SESSION['location'] = $location;
$_SESSION['location'] = $_POST['location'];
echo "Please save the link inorder to continue your survey http://bonnie/~jnagesh/SampleSurvey/OOPS/oopspage2.php";
}
else if($_POST['Operation2'])
{
$_SESSION['location'] = $location;
$_SESSION['location'] = $_POST['location'];
include "oopspage2.php";
}
elseif($_POST['Operation3'])
{
$_SESSION['effective'] = $effective;
$_SESSION['effective'] = $_POST['effective'];
$_SESSION['training'] = $training;
$_SESSION['training'] = $_POST['training'];
$_SESSION['treated'] = $treated;
$_SESSION['treated'] = $_POST['treated'];
$_SESSION['effort'] = $effort;
$_SESSION['effort'] = $_POST['effort'];
echo "Please save the link inorder to continue your survey later http://bonnie/~jnagesh/SampleSurvey/NextandBackButtons/page3.php";
}
elseif($_POST['Operation4'])
{
$_SESSION['effective'] = $effective;
$_SESSION['effective'] = $_POST['effective'];
$_SESSION['training'] = $training;
$_SESSION['training'] = $_POST['training'];
$_SESSION['treated'] = $treated;
$_SESSION['treated'] = $_POST['treated'];
$_SESSION['effort'] = $effort;
$_SESSION['effort'] = $_POST['effort'];
include "oopspage3.php";
}
elseif($_POST['Operation5']) /* THE PROBLEM LIES IN THIS CODE FOR BACK BUTTON*/
{
$location = $_POST['location'];
$_SESSION['location'] = $location;
<html>
<body>
<form action="1.php" method="post"> /*oBVIOUSLY i WONT BE ALLOWED TO DECLARE <HTML> INSIDE PHP*/
<input type="submit" value="back"/>
</form>
</body>
}
. . . . . . . . ?>
Не могли бы вы помочь мне, как реализовать кнопку «Назад». Заранее спасибо
Вы используете POST-операции, в результате чего ВСЕ браузеры будут жаловаться пользователю на повторную отправку ранее представленных данных. Вы не можете обойти это, если вы принципиально не измените, как работает ваша форма. –
Привет, Марк. Да, я знаю, что потребуется много времени, если мы будем использовать метод POST, но поскольку я очень новичок в php, это все, что я знаю. Есть ли способ, которым мы можем обойти это? Спасибо – Jathin
Это что-то, что связано с браузерами, и PHP не имеет ничего общего. Но вы можете сделать одно. Вы можете использовать вкладки, чтобы иметь предыдущий и следующий. Позвольте мне опубликовать ответ для этого. –