0

这是我的第一篇文章-对此非常陌生。我有一个联系表格,通过按一个按钮打开 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>";
  }
?>
4

0 回答 0