为什么我不能将数据从 Modal POST 到 PHP? [英] Why can't I POST data from a Modal to PHP?

查看:31
本文介绍了为什么我不能将数据从 Modal POST 到 PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码,一个带有 method="POST" 的表单中的模态,但在 php-part 中,提交的值不被读取.谁能告诉我如何做到这一点?

 <div class="容器"><button class="btn btn-success" data-toggle="modal" data-target="#myModal">启动模式<form method="post"><div class="modal" id="myModal"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title">您将在您的新电子邮件地址处收到一个访问代码</h4>

<div class="modal-body"><label for="text">在此处填写您的访问代码</label><input type="text" name="AccessCode" class="form-control"/>

<div class="modal-footer"><input type="submit" name="submit" value="Confirm" data-dismiss="modal" class="btn btn-success btn-lg marginTop"/>

</表单>

php 部分如下所示:

解决方案

表单需要一个动作..

不知道应该将信息发布到哪里.

会起作用..

要测试,在页面顶部的 php 部分添加

$testValue = "";if(isset($_POST["AccessCode"])){$testValue = $_POST["AccessCode"] ;echo "

带有访问代码的大写字母 :" .$testValue ."</h1>";}?>

现在在您的表单 HTML 项中使用 action="" 运行页面并测试表单.

分辨率:

而且您的提交似乎不能附加其他事件.. data-dismiss="modal".

Using the following code, a modal within a form with method="POST" but in the php-part the submitted value is not read. Can anyone tell me how to accomplish this?

                <?php
                if ($error) {
                    echo '<div class="alert alert-danger">'.$error.'</div>';
                }

                if ($message) {
                    echo '<div class="alert alert-success">'.$message.'</div>';
                }
                ?>

<div class="container"> 
    <button class="btn btn-success" data-toggle="modal" data-target="#myModal">
    Launch modal
    </button>

    <form method="post">                

    <div class="modal" id="myModal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">You will receive an Access Code at your new email-address</h4>
                </div>
                <div class="modal-body">
                    <label for="text">Fill in your Access Code right here</label>
                    <input type="text" name="AccessCode" class="form-control"/>
                </div>
                <div class="modal-footer">
                    <input type="submit" name="submit" value="Confirm" data-dismiss="modal" class="btn btn-success btn-lg marginTop" />
                </div>
            </div>
        </div>
    </div>

    </form>

</div>

The php part looks like this:

<?php 

if ($_POST['submit']=='Confirm') {
    print_r($_POST);
    $error="No errors";
    $message="Approved!";
} else {
    $error="Error!";
    $message="Nothing received";
}

?>

解决方案

Form needs an action ..

<form method="post">                

Has no idea where it is supposed to post the information to.

<form method="post" action="phpPageToSendTo.php">                

will work..

To test, at the top of your page in the php section add in

$testValue = "";
if(isset($_POST["AccessCode"]))
{
   $testValue = $_POST["AccessCode"] ;
   echo "<h1> BIG LETTERS WITH THE ACCESS CODE :" . $testValue . "</h1>";
}
?>

Now in your form HTML item use the action="" Run the page and test the form.

Resolution :

And it seems you cannot have another event attached to your submit.. data-dismiss="modal".

这篇关于为什么我不能将数据从 Modal POST 到 PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆