duanmoen784988 2013-09-05 12:46
浏览 91

jquery php电子邮件表单无法区分回调

I need to get this to distinguish between a successful and a failed submission.

send-email.php

$name = trim($_REQUEST['name']);
$email = trim($_REQUEST['email']);
$content = $_REQUEST['comment'];

if (eregi("",$email) || eregi("
",$email)){
 die("Why ?? :(");
}
$sitemail = "mail@mysite.com";
$ip='none';
$ip = getenv('REMOTE_ADDR');
if( $_SESSION['security_code'] != $_POST['security_code'] || empty($_SESSION['security_code'] ) ) {
    echo'<div class="message">The security code you entered did not match the image.</div>';
    return false;

}
else{
    //$sent=mail( $sitemail, "Message Title","From: $name 
 
 $message 

 $ip", "From: $email" );
    echo'<div class="message">Thank you for your message. We will get back to you as soon as possible.</div>';

}

Jquery:

jQuery("#contact-form").submit(function(e){
        var $form = jQuery(this),
        $msg = jQuery(this).prev('div.message'),
        $action = $form.attr('action');
        jQuery.post($action,$form.serialize(),function(data){
            $form.fadeOut("fast", function(){
                $msg.hide().html(data).show('fast');
            });
         });
        e.preventDefault();
  });

form

<div class="message"></div>

            <form id="contact-form" method="post"  action="send-email.php">
                <p class="column one-half">
                    <input name="name" type="text" placeholder="Your Name" required >
                </p>

                <p class="column one-half last">
                    <input name="email" type="email" placeholder="Your Email" required >
                </p>

                <p class="clear"><textarea name="comment" placeholder="Your Message" cols="5" rows="3" required></textarea>
                </p> 
                <p class="column one-third"><input id="security_code" type="text" placeholder="Enter Code in image" name="security_code" required></p>
                <img src="captcha/verifyimg.php?width=192&height=48" alt="Image verification" align="left" style="margin:10px;" />
                <p><input name="submit" type="submit" value="Send Message">
                </p>            
            </form>

I want to be able to get the form to stay visible if the form fails on the security_code.

So perhaps a response from the send-email.php is needed and then used with an 'if' clause. I have tried several ways to do this and couldn't even get it to distinguish between the callback results! I just seem to have gone round in circles. Any help appreciated.

  • 写回答

2条回答

  • dongzongzi0379 2013-09-05 13:01
    关注

    can you please check this code

    Jquery Code

    jQuery.ajax({
                url: jQuery('form#FrmQuote').attr("action"),
                type: "POST",
                dataType: 'json',       
                data: jQuery('form#FrmQuote').serialize()+'&action=SubmitQuote',
                success: function(data){
                    if(data['status']) {
                        // if it return success
                    } else {
                                 // if it return error
                        for(var id in data['error']) {
                                jQuery('#' + id).html(data['error'][id]);              
                        }
                    }
                    return false;
                }
            });
    

    PHP Code

    /* Submit Quote Form */

    if(isset($_POST['action']) && $_POST['action'] == 'SubmitQuote')
    {
        /*Retrive Data From Session */
        $price_cal_array = $__Session->GetValue("Sess_Calculator_Option");
    
        $SubmitQuoteResult  = array();      
    
        $Svalidation = false;       
        $err['FullNameError']   = isEmpty($_POST['fullname'],COMMON_FULLNAME_IS_REQUIRED)?isEmpty($_POST['fullname'],COMMON_FULLNAME_IS_REQUIRED):'';
        $err['EmailError']  = isEmpty($_POST['clientemail'],ERROR_EMAIL_ID_IS_REQUIRED)?isEmpty($_POST['clientemail'],ERROR_EMAIL_ID_IS_REQUIRED):'';
        $err['PhoneError']      = isEmpty($_POST['phonel'],COMMON_PHONE_IS_REQUIRED)?isEmpty($_POST['phone'],COMMON_PHONE_IS_REQUIRED):'';  
        $err['EnquiryError']        = isEmpty($_POST['enquiry'],COMMON_MESSAGE_IS_REQUIRED)?isEmpty($_POST['enquiry'],COMMON_MESSAGE_IS_REQUIRED):'';
        //$err['FullNameError'] = COMMON_FULLNAME_IS_REQUIRED;
        if (isset($_REQUEST['captcha_code'])) {
            require_once SITE_DOCUMENT_ROOT . '/new_captcha/securimage.php';
    
            $securimage = new Securimage();
    
            if ($securimage->check($_REQUEST['captcha_code']) == false) {
                $err['CaptchaError'] = CAPTCHA_INVALID;
            }
        }
    
        foreach($err as $key => $Value){
            if($Value != '') {
                $Svalidation=true;
            }
        }       
    
        if($Svalidation == false) {
    
            $SubmitQuoteResult['status']    = true;
            $SubmitQuoteResult['QuoteSubmitSuccessMsg'] = "success message";
            // send mail                    
        } else {
            $SubmitQuoteResult['status']    = false;
            $SubmitQuoteResult['error'] = $err;
        }
        echo json_encode($SubmitQuoteResult);
        exit;
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记