duankui3838 2016-06-10 16:12
浏览 94
已采纳

在bootstrap模态中说谢谢

I have a contact form in bootstrap that sending by email is works great. But I want to say "thank you and will get back to you" in bootstrap modal AFTER successful send the message.

My question is that how can I put the code to show the message "thank you " in the bootstrap modal AFTER successful send the message where it said @mail($email_to, $email_subject, $email_message, $headers);

<form name="contactform" method="post" action="send_form_email.php">
                    <div class="panel-body">
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-user blue"></i></span>
                                <input type="text" name="first_name" placeholder="Name" class="form-control" autofocus="autofocus" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-envelope blue"></i></span>
                                <input type="email" name="email" placeholder="Email" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-phone blue"></i></span>
                                <input type="number" name="telephone" placeholder="Phone" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-comment blue"></i></span>
                                <textarea name="comments" rows="3" class="form-control" type="text" required></textarea>
                            </div>
                        </div>
                        <div class="">
                        <button type="submit" class="btn btn-info pull-right" >Email Form</a>
                        Send <span class="glyphicon glyphicon-send"></span></button>
                            <button type="reset" value="Reset" name="reset" class="btn">Reset <span class="glyphicon glyphicon-refresh"></span></button>
                        </div>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

<div class="modal fade" id="modal-container-784141" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">

                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                ×
                            </button>
                            <h4 class="modal-title" id="myModalLabel">
                                Modal title
                            </h4>
                        </div>
                        <div class="modal-body">
                            ...
                        </div>
                        <grammarly>
                            <div class="_9b5ef6-textarea_btn _9b5ef6-not_focused">
                                <div class="_9b5ef6-transform_wrap">
                                    <div class="_9b5ef6-status">
                                    </div>
                                </div>
                            </div>
                        </grammarly>
                        <div class="modal-footer">

                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                Close
                            </button> 
                            <button type="button" class="btn btn-primary">
                                Save changes
                            </button>
                        </div>
                    </div>

                </div>

            </div>

        </div>

and

    <?php

if(isset($_POST['email'])) {



    // EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to = "xxxt";

    $email_subject = "Your email subject line";





    function died($error) {

        // your error code can go here

        echo "We are very sorry, but there were error(s) found with the form you submitted. ";

        echo "These errors appear below.<br /><br />";

        echo $error."<br /><br />";

        echo "Please go back and fix these errors.<br /><br />";

        die();

    }



    // validation expected data exists

    if(!isset($_POST['first_name']) ||

        !isset($_POST['email']) ||

        !isset($_POST['telephone']) ||

        !isset($_POST['comments'])) {

        died('We are sorry, but there appears to be a problem with the form you submitted.');       

    }



    $first_name = $_POST['first_name']; // required

    $email_from = $_POST['email']; // required

    $telephone = $_POST['telephone']; // not required

    $comments = $_POST['comments']; // required



    $error_message = "";

    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$email_from)) {

    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';

  }

    $string_exp = "/^[A-Za-z .'-]+$/";

  if(!preg_match($string_exp,$first_name)) {

    $error_message .= 'The First Name you entered does not appear to be valid.<br />';

  }

  if(strlen($comments) < 2) {

    $error_message .= 'The Comments you entered do not appear to be valid.<br />';

  }

  if(strlen($error_message) > 0) {

    died($error_message);

  }

    $email_message = "Form details below.

";



    function clean_string($string) {

      $bad = array("content-type","bcc:","to:","cc:","href");

      return str_replace($bad,"",$string);

    }



    $email_message .= "First Name: ".clean_string($first_name)."
";

    $email_message .= "Email: ".clean_string($email_from)."
";

    $email_message .= "Telephone: ".clean_string($telephone)."
";

    $email_message .= "Comments: ".clean_string($comments)."
";





// create email headers

$headers = 'From: '.$email_from."
".

'Reply-To: '.$email_from."
" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);




?>




<?php

}

?>
  • 写回答

1条回答 默认 最新

  • douchu2823 2016-06-10 17:33
    关注

    I assume you are going to show your thank you modal-dialog in your php code, so here's the code I made (based on your php code) :

        <?php
    
    if(isset($_POST['email'])) {
    
    
    
        // EDIT THE 2 LINES BELOW AS REQUIRED
    
        $email_to = "xxxt";
    
        $email_subject = "Your email subject line";
    
    
    
    
    
        function died($error) {
    
            // your error code can go here
    
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    
            echo "These errors appear below.<br /><br />";
    
            echo $error."<br /><br />";
    
            echo "Please go back and fix these errors.<br /><br />";
    
            die();
    
        }
    
    
    
        // validation expected data exists
    
        if(!isset($_POST['first_name']) ||
    
            !isset($_POST['email']) ||
    
            !isset($_POST['telephone']) ||
    
            !isset($_POST['comments'])) {
    
            died('We are sorry, but there appears to be a problem with the form you submitted.');       
    
        }
    
    
    
        $first_name = $_POST['first_name']; // required
    
        $email_from = $_POST['email']; // required
    
        $telephone = $_POST['telephone']; // not required
    
        $comments = $_POST['comments']; // required
    
    
    
        $error_message = "";
    
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    
      if(!preg_match($email_exp,$email_from)) {
    
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    
      }
    
        $string_exp = "/^[A-Za-z .'-]+$/";
    
      if(!preg_match($string_exp,$first_name)) {
    
        $error_message .= 'The First Name you entered does not appear to be valid.<br />';
    
      }
    
      if(strlen($comments) < 2) {
    
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
    
      }
    
      if(strlen($error_message) > 0) {
    
        died($error_message);
    
      }
    
        $email_message = "Form details below.
    
    ";
    
    
    
        function clean_string($string) {
    
          $bad = array("content-type","bcc:","to:","cc:","href");
    
          return str_replace($bad,"",$string);
    
        }
    } else {
        ?>
    
        <!-- Modal Thank You -->
    <div id="input_barang" class="modal fade" role="dialog">
      <div class="modal-dialog modal-sm">
    
        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <!--<h4 class="modal-title">Input Jenis Barang</h4>-->
          </div>
          <div class="modal-body">
            
            Than You !
    
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
    
      </div>
    </div>
    
    <?php } ?>

    You did not close your first 'if' statement with '}' so I added the else statement on that first 'if' statement located above your clean_string function. Hope it helps, good luck!

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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