Page 1 of 1
[Solved] Form fields
Posted: Fri Jan 11, 2008 10:39 pm
by dharprog
Hi
I would like to know form fields shouldnt disappear when you comeback to the same page after submitting a form.
Suppose if we take any registration form, After filling all the form fields we click on submit after this when we come back to the same form page by clicking on back button the form filled values are disappearing which i dont want. Please let me know how to get the form having the filled input fields when click on back button without disappear.
Please kindly help.
Thank you very much.
Regards,
DharProg.
Re: Form fields
Posted: Sat Jan 12, 2008 3:08 am
by hannnndy
usgae form:
you have two way to send a data to another page
1.POST
2.GET
Code: Select all
<form action=index.php method="POST">
<input type=text name='fieldName'>
<input type=submit>
</form>
index.php :
1.$_POST //post method
2.$_GET //get method
3.$_REQUEST // both methods
Code: Select all
<?php
$field=$_POST['fieldName'];
echo($field);
?>
Re: Form fields
Posted: Sat Jan 12, 2008 1:15 pm
by Jonah Bron
When you push the back button, it should still be there. Now, if there is a link, that's a different story. You would have to use php:
Code: Select all
<?php
//what you are doing with the info
?>
<a href="index.php?box1=<?php echo $_REQUEST['box1']; ?>&box2=<?php echo $_REQUEST['box2']; ?>">Back to the form</a>
Then, back at the form (index.php)
Code: Select all
<input type="text" name="box1" value="<?php if (isset($_REQUEST['box1'])) echo $_REQUEST['box1']; ?>" />
<input type="text" name="box2" value="<?php if (isset($_REQUEST['box2'])) echo $_REQUEST['box2']; ?>" />
<input type="submit" value="Submit" />
Re: Form fields
Posted: Sat Jan 12, 2008 9:21 pm
by dharprog
Hi
Thanks for the response.
I dont think this is the right answer, We can use sessions too for that.
May be some other solution would be there.
Thank you.
Regards,
Dhar Prog.
Re: Form fields
Posted: Sat Jan 12, 2008 10:04 pm
by superdezign
I believe it's known as sticky values (or some variation of 'sticky' something). You simply post the form to the same page and display the posted values in the fields. Here's an example.
Code: Select all
<?php
if (!empty($_POST)) {
// Validate information, process it, and possibly redirect if it's all valid
}
if ($informationIsNotValid) {
?>
<form action="#" method="post">
<input type="text" name="fieldName" value="<?php echo isset($_POST['fieldName']) ? $_POST['fieldName'] : ''; ?>" />
<textarea name="otherFieldName"><?php echo isset($_POST['otherFieldName']) ? $_POST['otherFieldName'] : ''; ?></textarea>
</form>
<?php
}
?>
Re: Form fields
Posted: Sat Jan 12, 2008 11:27 pm
by John Cartwright
Typically what is done is after a form submission has taken place, the form data is saved inside the session, then a redirect header is done to avoid reposting the same data when using the back button.
1. User visits form.php
2. User posts the form to form.php
3. form.php saves form data in session, i.e. $_SESSION['post'] = $_POST;
4. form.php redirects to itself (or another processing page)
Code: Select all
header('Location: http://domain.com/form.php');
5. form.php reads the $_SESSION['post'] to determine the next course of action.
Re: Form fields
Posted: Tue Jan 15, 2008 2:57 am
by dharprog
Hi
Thats great, both the solutions from both Jcart and superdezign are perfect.
Its solved.
Thanks for the reply.
Regards,
DharProg.