Quote:
Originally posted by SteveSoler
The actions I want the user to take are as follows:
1) Fill out form.
2) Press Preview Button (the only button on that page).
3) Look over preview of text entered. (this should be on a new page and appear as text, not text in form fields.)
4a) If user finds mistake in text of Preview, click Edit button (or link or Browser back button) to go back to form and make changes. Then user repeats steps 1 (editing not re-entering data) through 4.
4b) If user does not find mistakes in text of Preview, clicks submit button that INSERTS form data into MySQL table.
5) User gets a new page thats says "thank you. form submitted."
Does the script/s you are working on function like this?
|
The page code I displayed will work in a similar way, the first page the user will have displayed, (At this time no info has been entered into the form fields) is a page, where theres only the form itself, with a single 'submit' button. (you could make a small check, that would display it as 'preview' and on submit change it to 'submit')
Uppon clicking the submit button, after fillining the form, the user will see a page, where the top part will be a sample of how the info in the form will be displayed. (The
echo "your current issue... part will display that)
The second half of the page, will be the form once again, this time with the info the user submitted allready entered into the fields.
Uppon editing (or what ever the user feel is needed) he presses submit once again, and this time the values of the input fields, will be stored into the database, with no chance of previewing.
That was just the way my tired head thought this up. It's easy because you use the same segment of code for the form, no matter if its the first time viewed, with no data entered into any field, or if it's the second time, with the preview displayed.
In your requirements, you'll need two submit buttons, each sending different infos, where the first time viewed, only one will be displayed.
But to follow your requirements, here's this days shot at it (mind that this next code segment hasn't been tested in any way, its directly written into the reply form, just like yesterdays code, it comes with no warentie)
Code:
<?php
if(!isset($view) || isset($edit) || $view == 1)
{
/* this condition should cover the following:
1) First view here, no values in fields yet
2) Preview time, $view should be 1 now.
3) Edit time, $view is 2, but who cares lets edit
*/
if(isset($preview))
{
/* we only want this part displayed if it
truely is a 'preview' press that directed
us here
*/
echo "your current issue is:<br>
some setup of how the $whatever_fieldnames should be shown";
$type = "hidden";
}
else
{
/* only solution to end here, at this point,
is if 'edit' has been pressed, or its a
first view, so it's safest to set $view to 0
*/
$type = "text";
$view = 0;
}
echo "
<form action='$PHP_SELF' method=post>
<input type='hidden' value='$view+1' name='view'>
<input type='$type' name='some_field' value='$some_field'>
<!-- and so on with the rest of the fields used -->
";
if($view == 0)
{
/* first time here, or we are editing it.
only preview available
*/
echo "<input type='submit' name='preview' value='preview'>";
}
else
{
/* second time, alot of options */
echo "<input type='submit' name='edit' value='edit'>
<input type='submit' name='submit' value='submit'>";
}
echo "
</form>";
}
else
{
/* The 'submit' must've been pushed
insted of edit or preview, so we want it
into the database for good
*/
$DB=mysql_connect("localhost", "user", "passwd");
mysql_select_db("some_db");
mysql_query("INSERT INTO whatever VALUES (some_field='$some_field' ...)", $DB);
header("Location: /what/ever/page.php");
}
?>
As you can se, the
$type can only be set to 'text', so if you have more than that type of input field, create a
$type_field for each of those.
The page functionality is now as this:
1) first time here, only a form, with input fields and a single preview button
2) preview is pressed, and you see a preview of how its gonna be, a 'edit' and a 'submit' button displayed.
3a) pressing 'edit' results in step 1, with the fields holding the values allready in use.
3b) pressing 'submit' results in submitting data to database, and redirecting to /what/ever/page.php.
Was that how it was intended ?
I'm beginning to lose objectivity in this small input field.. But I think every possible outcome has been covered.