weixin_33691817 2018-05-14 12:11 采纳率: 0%
浏览 18

提交表格后显示弹出窗口

can anyone help me, I want the result of php to be displayed in pop up form on the same html page, how can that do? this is my code thank you all for help

index.html

        <!-- Start Contact Form -->
    <div class="triangle"></div>
    <div id="cform" class="container">
        <div class="row">
            <h3 class="my-title contact-title">Kontaktformular</h3>
            <hr>
            <div class="col-md-12">
                <form id="my-form" method="post" action="handler.php">
                    <ul class="contact-form">
                        <li>
                            <div class="col-md-6">
                                <input name="name" placeholder="Name" required="required" size="8" type="text">
                            </div>

                            <div class="col-md-6">
                                <input name="email" placeholder="E-Mail" required="required" size="8" type="email">
                            </div>
                        </li>

                        <li>
                            <div class="col-md-6">
                                <input name="telefon" placeholder="Telefon" size="8" type="text">
                            </div>

                            <div class="col-md-6">
                                <input name="firma" placeholder="Firma" size="8" type="text">
                            </div>
                        </li>

                        <li>
                            <div class="col-md-6">
                                <label>Ihr Budget</label>
                                <div id="slider-range-min" class="ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all">
                                    <div class="ui-slider-range ui-widget-header ui-corner-all ui-slider-range-min" style="width: 1%;">
                                        </div><span class="ui-slider-handle ui-state-default ui-corner-all" tabindex="0" style="left: 8%;"></span></div>
                            </div>
                            <div class="col-md-6">
                                <input name="amount" id="amount" readonly>
                            </div>
                        </li>

                        <li>

                            <div class="col-md-12">
                                <textarea class="span12" name="details" placeholder="Ihre Projektbeschreibung" required="required"></textarea>
                            </div>
                        </li>

                        <li>
                            <div class="col-md-12">
                                <button id="my-btn" type="submit">Senden <span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span></button>
                                <span id="status"></span>
                            </div>
                        </li>


                    </ul>
                </form>
            </div>

        </div>
    </div>
    <!-- End Contact Form -->

handler.php

<?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "info@test.com";
    $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['name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telefon']) ||
        !isset($_POST['firma']) ||
        !isset($_POST['amount']) ||
        !isset($_POST['details'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }



    $first_name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $firma = $_POST['firma']; // required
    $telephone = $_POST['telefon']; // not required
    $amount = $_POST['amount'];
    $comments = $_POST['details']; // 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(!preg_match($string_exp,$firma)) {
    $error_message .= 'The Last 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 .= "Firma: ".clean_string($firma)."
";
    $email_message .= "Amount: ".clean_string($amount)."
";
    $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);  


?>

<!-- include your own success html here -->


Thank you for contacting us. We will be in touch with you very soon.


<?php

}
?>

I apologize for the fact that I put the php code in the snippet, I could not possibly put it differently, but I think it is as clear as that.

At the moment when I send the form I get on the second page ie handler.php answer that the form is sent ("Thank you for contacting us. We will be in touch with you very soon.")

  • 写回答

4条回答 默认 最新

  • weixin_33736048 2018-05-14 12:15
    关注

    You have to add target attribute to the form HTML tag. There you can specify an ID of an iframe placed inside your popup.

    <form target="my-iframe"></form>
    
    <div class="popup">
    <iframe id="my-iframe"/>
    </div>
    

    You don't have to use JS at all :) Unless I'm mistaken ... See the reference: https://www.w3schools.com/tags/att_form_target.asp

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加