Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Save and Exit Button?

Status
Not open for further replies.

RENO9

Technical User
Dec 8, 2005
27
GB
I have a page with a coulple of forms which contain everything from radio buttons, check boxes, select lists and text boxes.
I would like the user to have the option to save and exit at anytime, so if they have only done half a form they can save what they have done into the database and exit.

The 1st step would be to get an option just to 'Save & Exit' but to develop this further into a prompt giving the user the options of 'Save & Exit', 'Dont Save & Exit' and 'Return to form'

Any suggestions on how to go about this?
Thanks
 
unless you have got any server or client side validation and unless your database table schema prevents this, there should be nothing to do. submitting the form will send what is currently in the form fields and your scripts will parse them and write them to the database.

if you wanted to give the user a chance to return and fill more out later then you might consider serialising the form values and saving them in a session store.
 
Submit buttons in HTML forms can also return values. For example, the HTML page:

Code:
<html>
	<body>
		<form method="POST" action="show_post.php">
			<input type="text" name="foo"><br>
			<input type="submit" name="submit_type" value="Save and Exit">
			<input type="submit" name="submit_type" value="Discard and Exit">
			<input type="submit" name="submit_type" value="Return to Form">
		</form>
	</body>
</html>

BTW show_post.php reads:

Code:
<?php
print '<html><body><pre>';

print_r ($_POST);

print '</pre></body></html>';
?>

By having a value and name on the button, when the buttons are clicked, the script to which the form is submitted can do multiple things. Perhaps if your script has the general form of:

Code:
switch ($_POST['submit_type'])
{
	case 'Save and Exit':
		// save what we have so far
		// send browser to another page in the site
		break;
	case 'Discard and Exit':
		//throw away what we have so far
		// send browser to another page in the site
		break;
	case 'Return to Form':
		//I'm not sure what this would do, but it's in here
		break;
}



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks for the quick responses, il give sleipnir214's suggestion a shot and see how it goes.

Cheers
 
You should also be aware that in case the user presses enter in any of the fields the form will be submitted using the first submit button but IE will not be sending the value. In that respect it is good to have a default action in your switch to catch those instances.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top