Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery - Hide form on Submit
    primarykey
    data
    text
    <p>I would like to hide my form on successful submission:</p> <p>Here is a link to the testspace: <a href="http://www.bgv.co.za/testspace/contact_3.php" rel="nofollow">http://www.bgv.co.za/testspace/contact_3.php</a></p> <p>Its a combination PHP jQuery mongrel. At the moment I'm using jQuery validator and I have added custom script to change the class on the input fields wrapping div - as a way to show required fields.</p> <p>Here is what I have in the PHP</p> <pre><code>&lt;?php </code></pre> <p>$subject = "Website Contact Form Enquiry";</p> <p>//If the form is submitted if(isset($_POST['submit'])) {</p> <pre><code>//Check to make sure that the name field is not empty if(trim($_POST['contactname']) == '') { $hasError = true; } else { $name = trim($_POST['contactname']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { $emailTo = 'info@bgv.co.za'; //Put your own email address here $body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments"; $headers = 'From: My Site &lt;'.$emailTo.'&gt;' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } </code></pre> <p>} ?></p> <p>and here is the script area:</p> <pre><code>$(document).ready(function(){ $('#contactform').validate({ showErrors: function(errorMap, errorList) { //restore the normal look $('#contactform div._required').removeClass('_required').addClass('xrequired'); //stop if everything is ok if (errorList.length == 0) return; //Iterate over the errors for(var i = 0;i &lt; errorList.length; i++) $(errorList[i].element).parent().removeClass('xrequired').addClass('_required'); } </code></pre> <p>}); });</p> <p>So at the moment when someone submits a valid form you see a new heading just under Contact form - its from here: </p> <pre><code> &lt;?php if(isset($emailSent) &amp;&amp; $emailSent == true) { //If email is sent ?&gt; &lt;h1 class="success_form"&gt;Thank You!&lt;/h1&gt; &lt;?php } ?&gt; </code></pre> <p>and below it is the data entered into the form.</p> <p>But its the form shoing below that I want to hide.... Please help :)</p> <p>Here is the new bit I added thanks to Flashbackzoo</p> <pre><code> $("#content").empty(); $("#content").append( "&lt;p&gt;If you want to be kept in the loop...&lt;/p&gt;" + "&lt;p&gt;Or you can contact...&lt;/p&gt;" ); $('h1.success_').removeClass('success_').addClass('success_form'); $('#contactform').hide(); }, </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload