PHP Clear Form

Hello All,

I consider my self a little above a newbie status with php and need your expert advise. I have a form in the following URL http://www.hurlburtservicesonline.com/pages/marquee_request.php and want to be able to clear the form once the submit button has been submitted as long as no missing fields are missing. Please help!:confused:

Unless you want the page to refresh, this has to be done with Javascript. Once the page is submitted you have to validate all of the fields using Javascript. If there are no errors with the Javascript validation then submit the form and empty the fields.

ok thanks.

One more question.

What if I wanted to reload a different page which recieved variables for the php script that sent the email?

Thanks!

I would advice against JavaScript validating as it can by bypassed by turning off JavaScript in browsers. You would need to do the validating process on the server-side, and could possibly degrade with JavaScript validation at the same time, if you wanted a more secure & user-friendly approach.

About reloading a different page, do you mean the page that suppose to process the submitted data? If yes, then you should point to that page in the action attribute value:


<form action="yourdesiredoage.php" method="post">

as opposed to submitting the form data to the same page:


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

If you want to “redirect” to another page, say, a “Thanks for submission” page, you would want to use the header() function:


header('Location: http://www.example.com/newpage.php');

If you visit the page http://www.hurlburtservicesonline.com/pages/marquee_request2.php and just test out the form. I have the exact response I want reloading on the form page. What I want to ulitmately do is have the response show up in a popup and then if it does send an email clear the form if it doesnt keep the form fields they entered.

Sorry if i sound confusing.

You could use PHP’s output buffering ob_start() function with a callback.


<?php

function callback($response) {
    if !mail() {
        // Do the following
        ...
        return $response;
    } else {
        // Do the following
        ...
        return $response;
    }
}

ob_start('callback');

?>

<html>

HTML code goes here, including maybe your form code

</html>

<?php ob_end_flush() ?>


Not a perfect demonstration, but I guess you get the idea. Check the manual for full investigation of output buffering in PHP.

Hi simsim,

Unfortunately I don’t know a thing about how output buffering works. I read a little about it online but don’t understand how it works.