title: php contact form with jquery style
body: <p>This is my first post - very very new to this. I have a contact form which opens with jquery by pressing a button. When I submit this form using php, the box closes again so you can only see the 'view form' button. When I click on this the box/form opens again and although the form is submitted - I would like the box to stay open to display the 'thank you for submitting etc' message - any help would be appreciated. thanks. Here is my jquery and php:</p>
  
  <pre><code>(function() {
      $('html').addClass('js');
      var contactForm = {
      container: $('#contact'),
  
      config: {
          effect: 'slideToggle',
          speed: 500
      },
  
      init: function(config) {
          $.extend(this.config, config);
  
          $('&lt;button&gt;&lt;/button&gt;', {
              text: 'view form'
          })
              .insertAfter( '.show-form' )
              .on( 'click', this.show );
      },
  
      show: function() {
          var cf = contactForm,
              container = cf.container,
              config = cf.config;
  
          if ( container.is(':hidden') ) {
              contactForm.close.call(container);
              container[config.effect](config.speed);
          }
      },
  
      close: function() {
          var $this = $(this), // #contact
              config = contactForm.config;
  
          if ( $this.find('span.close').length ) return;
  
          $('&lt;span class=close&gt;X&lt;/span&gt;')
              .prependTo(this)
              .on('click', function() {
                  // this = span
                  $this[config.effect](config.speed);
              })
          }
      };
              contactForm.init({
          // effect: 'fadeToggle',
          speed: 300
      });
  
  })();
  
  
  &lt;form&gt;
  
  &lt;?php
  function spamcheck($field)
    {
    //filter_var() sanitizes the e-mail
    //address using FILTER_SANITIZE_EMAIL
    $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  
    //filter_var() validates the e-mail
    //address using FILTER_VALIDATE_EMAIL
    if(filter_var($field, FILTER_VALIDATE_EMAIL))
      {
      return TRUE;
      }
    else
      {
      return FALSE;
      }
    }
  
  if (isset($_REQUEST['email']))
    {//if "email" is filled out, proceed
  
    //check if the email address is invalid
    $mailcheck = spamcheck($_REQUEST['email']);
    if ($mailcheck==FALSE)
      {
      echo "Error - Please check your details";
      }
    else
      {//send email
      $email = $_REQUEST['email'] ;
      $subject = $_REQUEST['subject'] ;
      $message = $_REQUEST['message'] ;
      mail("myemail@hotmail.co.uk", "Subject: $subject",
      $message, "From: $email" );
      echo "Thank you for your query.";
      }
    }
  else
    {//if "email" is not filled out, display the form
    echo "&lt;form method='post' action='thanks.php'&gt;
    Email: &lt;input name='email' type='text' /&gt;&lt;br /&gt;&lt;br /&gt;
    Subject: &lt;input name='subject' type='text' /&gt;&lt;br /&gt;&lt;br /&gt;
    Message:&lt;br /&gt;
    &lt;textarea name='message' rows='5' cols='40'&gt;
    &lt;/textarea&gt;&lt;br /&gt;
    &lt;input type='submit' /&gt;
    &lt;/form&gt;";
    }
  ?&gt;
  </code></pre>