简体   繁体   English

用PHP触发Bootstrap模态

[英]Trigger Bootstrap modal with PHP

I need to trigger a Bootstrap modal after a Bootstrap form has been submitted successfully. 成功提交Bootstrap表单后,我需要触发Bootstrap模态。 I have tried using the javascript line, but don't know how to trigger a modal from PHP? 我尝试使用javascript行,但不知道如何从PHP触发模式?

<?php
    $title = $_POST['title'];
    $fname = $_POST['fname'];
    $surname = $_POST['surname'];
    $contactno = $_POST['contactno'];
    $email = $_POST['email'];
    $roomno = $_POST['roomno'];
    $address = $_POST['address'];
    $town = $_POST['town'];
    $county = $_POST['county'];
    $postcode = $_POST['postcode'];
    $floorplan = $_POST['floorplan'];
    $from = 'sentMessage'; 
    $to = 'example.com'; 
    $subject = 'Quote Request';
    $body ="From: $title\n fname : $surname\n conatctno : $email\n roomno : $address\n town : $county\n postcode : \n $floorplan";

// If there are no errors, send the email

    if (mail ($to, $subject, $body, $from)){
        setcookie("success","success", time() +100, "/" );
        header('location: index.php');

    }else{
        setcookie("error","error", time() +100, "/" );
        header('location: index.php');
    };

?>      

Pass a value to the view, like 将值传递给视图,例如

$msg = true;

when want to fire the modal. 当要触发模态时。 check if the variable has been set in javascript: 检查变量是否已在javascript中设置:

var msg = "<?php echo $msg ?>";
if(msg == "1") {
  // fire here the modal,  like
  $('#hidden-modal-handle').click();
  // where hidden-modal-handle in this case is the id       of the anchor tag that fires the modal
}

Put the js code inside $(document).ready function 将js代码放入$(document).ready函数中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM