邮件脚本无法正常工作

时间:2013-06-09 10:13:01

标签: php javascript jquery html5 email


我找到了关于如何创建甜蜜联系表单的指南,遗憾的是它不起作用。 http://www.hongkiat.com/blog/ajax-html5-css3-contact-form-tutorial/

所以这是我的形式:`                 您的电子邮件已发送。好哇!

            

        <?php if(isset($hasError) || isset($captchaError) ) { ?>
                    <p class="alert">Error submitting the form</p>
                <?php } ?>
            <form id="contact-us" action="index.php" method="post">
            <label class="formtitle">Name</label>
            <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="text requiredField" />
                        <?php if($nameError != '') { ?>
                            <br /><span class="error"><?php echo $nameError;?></span> 
                        <?php } ?>
            <label class="formtitle">Email</label>
           <input type="text" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="text requiredField email" />
                        <?php if($emailError != '') { ?>
                            <br /><span class="error"><?php echo $emailError;?></span>
                        <?php } ?>
            <label class="formtitle">Message</label>
            <textarea name="comments" id="commentsText" class="textmessage requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
                        <?php if($commentError != '') { ?>
                            <br /><span class="error"><?php echo $commentError;?></span> 
                        <?php } ?>
            <button name="submit" type="submit" class="formbutton">Send!</button>
            <input type="hidden" name="submitted" id="submitted" value="true" />
            </form>
           <?php } ?> 

因此,当点击提交按钮时,它会启动脚本:

$('form#contact-us').submit(function() {
        $('form#contact-us .error').remove();
        var hasError = false;
        $('.requiredField').each(function() {
            if($.trim($(this).val()) == '') {
                var labelText = $(this).prev('label').text();
                $(this).parent().append('<span class="error"><br>Je bent vergeten je '+labelText+' in te vullen.</span>');
                $(this).addClass('inputError');
                hasError = true;
            } else if($(this).hasClass('email')) {
                var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
                if(!emailReg.test($.trim($(this).val()))) {
                    var labelText = $(this).prev('label').text();
                    $(this).parent().append('<span class="toa"><br>Sorry! Je e-mailadres is ongeldig.</span>');
                    $(this).addClass('inputError');
                    hasError = true;
                }
            }
        });
        if(!hasError) {
            var formInput = $(this).serialize();
            alert(formInput);
            $.post($(this).attr('action'),formInput, function(data){
                $('form#contact-us').slideUp("fast", function() {                  
                    $(this).before('<p class="error"><strong>Bedankt voor je bericht!</strong> Je krijgt zo spoedig mogelijk antwoord!</p>');
                });
            });
        }

        return false;   
    });

问题是它没有启动PHP脚本在$ .post($(this).attr('action')中调用的内容...
if(isset($_POST['submitted'])) { echo '<script type="text/javascript"> alert("Text!") </script>'; // require a name from user if(trim($_POST['contactName']) === '') {
我没有得到警报框,所以由于某种原因它只是不起作用,我真的不知道为什么..

0 个答案:

没有答案