php与jquery风格的联系表单

时间:2013-05-15 07:06:19

标签: php jquery forms post

这是我的第一篇文章 - 对此非常新。我有一个联系表单,按下按钮打开jquery。当我使用php提交此表单时,该框会再次关闭,因此您只能看到“查看表单”按钮。当我点击这个时,盒子/表格再次打开,虽然表格已经提交 - 我希望盒子保持打开状态,以显示“谢谢你提交等”的消息 - 任何帮助将不胜感激。谢谢。这是我的jquery和php:

(function() {
    $('html').addClass('js');
    var contactForm = {
    container: $('#contact'),

    config: {
        effect: 'slideToggle',
        speed: 500
    },

    init: function(config) {
        $.extend(this.config, config);

        $('<button></button>', {
            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;

        $('<span class=close>X</span>')
            .prependTo(this)
            .on('click', function() {
                // this = span
                $this[config.effect](config.speed);
            })
        }
    };
            contactForm.init({
        // effect: 'fadeToggle',
        speed: 300
    });

})();


<form>

<?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 "<form method='post' action='thanks.php'>
  Email: <input name='email' type='text' /><br /><br />
  Subject: <input name='subject' type='text' /><br /><br />
  Message:<br />
  <textarea name='message' rows='5' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

0 个答案:

没有答案