Log in

View Full Version : Simple form question



jzhang1013
05-23-2009, 04:10 PM
Hey all, so I built a simple email form and I want the form to go to a "Submission Successful" is there anyway to do this without redirecting to another page? I just want to form to be gone after they submit so they don't submit twice.

Thanks,
John

traq
05-24-2009, 02:07 AM
show us your code. You can use a conditional statement to present the form -or- a success message, depending on if the form has been submitted or not.

jzhang1013
05-24-2009, 04:50 AM
ok this is what I have so far, it'll show the message but the form stays put, but I want ti to go away.


function success($wufoo_response){
$success = $response->submit[0]->success;
if ($success == "true") echo "Thanks for filling out my survey! I will take into consideration your input and modify this site to suit you! Enjoy!";
else return false;
}

traq
05-24-2009, 07:11 PM
what action does your form have? do you submit to a different page, or is the form submission processed on the same page as the form appears?

Something like this is what I'm thinking:


<?php
if (!isset($_POST['formsubmission'])) { //if form is not yet submitted, the form will display
echo "<form action=\"".$_SERVER['PHP_SELF']."\">
"//form goes here
"<input type=\"submit\" name=\"formsubmission\" value=\"Submit\">";
}
else { //if the form was submitted, then the submission will be processed and success message displayed - form is not displayed
//code to process form
//then, echo your success message here
}
?>

jzhang1013
05-25-2009, 05:28 AM
the successful message shows on the form page (same page)

traq
05-25-2009, 05:39 AM
the successful message shows on the form page (same page)

yes, but where is the form submission processed? what is the action attribute of the form?

echo "<form action=\"???\">" //is the form processed on the same page?
If the same page shows and processes the form, you can use the if...else statement to show the form if it hasn't been submitted, or the success message if it has.

jzhang1013
05-25-2009, 05:30 PM
<form id="form2" name="form2" class="wufoo topLabel" autocomplete="off"
enctype="multipart/form-data" method="post" action="#public">

yes it is.

traq
05-25-2009, 06:31 PM
okay, so:


<?php
if(!isset($_POST['form2'])){
echo ""; //put form here
} else {
// process your form here and set $success to true if successful
if ($success == true) {
echo "Thanks for filling out my form";
} else {
echo "There was a problem! Please try again";
}
?>

jzhang1013
05-25-2009, 08:25 PM
so by using the above code the form will disappear and the success message will appear in its places correct?

traq
05-25-2009, 10:58 PM
it should. put your existing code in the correct places and try it out. Basically, the "if" tells your server that, if the form hasn't been posted, to display the form; and if it has, to process it.
Let me know how it goes.