[Solved] Form fields
Moderator: General Moderators
[Solved] Form fields
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.
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.
Last edited by dharprog on Tue Jan 15, 2008 2:58 am, edited 1 time in total.
- hannnndy
- Forum Contributor
- Posts: 131
- Joined: Sat Jan 12, 2008 2:09 am
- Location: Iran>Tehran
- Contact:
Re: Form fields
usgae form:
you have two way to send a data to another page
1.POST
2.GET
index.php :
1.$_POST //post method
2.$_GET //get method
3.$_REQUEST // both methods
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>1.$_POST //post method
2.$_GET //get method
3.$_REQUEST // both methods
Code: Select all
<?php
$field=$_POST['fieldName'];
echo($field);
?>- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Form fields
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:
Then, back at the form (index.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>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
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.
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.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Form fields
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
}
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Form fields
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)
5. form.php reads the $_SESSION['post'] to determine the next course of action.
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'); Re: Form fields
Hi
Thats great, both the solutions from both Jcart and superdezign are perfect.
Its solved.
Thanks for the reply.
Regards,
DharProg.
Thats great, both the solutions from both Jcart and superdezign are perfect.
Its solved.
Thanks for the reply.
Regards,
DharProg.