Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提交模型表单时,希望在php变量中发布值_Php_Jquery - Fatal编程技术网

提交模型表单时,希望在php变量中发布值

提交模型表单时,希望在php变量中发布值,php,jquery,Php,Jquery,感谢大家对我上一个问题的帮助 现在我又陷入了困境 问题:我正在使用模型表单提交密码。提交模型表单时,我想以$u POST或$u请求的形式调用操作。但我无法在php代码中获得post操作。下面是我的代码 文件名:password.php <?php // i try both method if($_SERVER['REQUEST_METHOD'] == 'POST') { v

感谢大家对我上一个问题的帮助

现在我又陷入了困境

问题:我正在使用模型表单提交密码。提交模型表单时,我想以$u POST或$u请求的形式调用操作。但我无法在php代码中获得post操作。下面是我的代码

文件名:password.php

          <?php
            // i try both method
            if($_SERVER['REQUEST_METHOD'] == 'POST')
            {
            var_dump($_REQUEST['data']); die;
            }

            /*if($_REQUEST['data'])
            {
                $password=$_REQUEST['data'];   

                var_dump($password);
             die;
            }*/
            ?>
            <!doctype html>
            <html lang="en">
            <head>
            <meta charset="utf-8">
            <title>Reset Password</title>
            <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
            <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
            <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
            <style>
            body { font-size: 62.5%; }
            label, input { display:block; }
            input.text { margin-bottom:12px; width:95%; padding: .4em; }
            fieldset { padding:0; border:0; margin-top:25px; }
            h1 { font-size: 1.2em; margin: .6em 0; }
            div#users-contain { width: 350px; margin: 20px 0; }
            div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
            div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
            .ui-dialog .ui-state-error { padding: .3em; }
            .validateTips { border: 1px solid transparent; padding: 0.001em; }
            .ui-dialog-titlebar-close {display:none !important;}
            </style>
            <script>
            $(function() 
            {
                var password = $( "#password" ), RePassword = $( "#RePassword" ), allFields = $( [] ).add(password).add(RePassword ),tips = $( ".validateTips" );
                function updateTips( t ) 
                {
                    tips.text( t ).addClass( "ui-state-highlight" );
                    setTimeout(function() 
                    {
                        tips.removeClass( "ui-state-highlight", 1500 );
                    }, 500 );
                }
                function checkLength( o, n, min, max ) 
                {
                    var pass=password.val();
                    var repass=RePassword.val();
                    if ( o.val().length > max || o.val().length < min ) 
                    {
                        o.addClass( "ui-state-error" );
                        updateTips( "Length of " + n + " must be between " + min + " and " + max + "." );
                        return false;
                    }
                    else if(pass != repass)
                    {
                        o.addClass( "ui-state-error" );
                        updateTips( "password not match." );
                        return false;
                    }
                    else 
                    {
                        return true;
                    }
                }
                function checkRegexp( o, regexp, n ) 
                {
                    if ( !( regexp.test( o.val() ) ) ) 
                    {
                        o.addClass( "ui-state-error" );
                        updateTips( n );
                        return false;
                    } 
                    else 
                    {
                        return true;
                    }
                }
                $( "#dialog-form" ).dialog(
                {
                    closeOnEscape: false,
                    autoOpen: true,
                    height: 250,
                    width: 300,
                    modal: true,
                    buttons: {
                        "submit": function(e) {
                            var bValid = true;
                            allFields.removeClass( "ui-state-error" );
                            bValid = bValid && checkLength( password, "password", 8, 16 );
                            bValid = bValid && checkLength( RePassword, "RePassword", 8, 16 );

                            if ( bValid ) {
                            e.preventDefault();
                                $.ajax({
                                    type: "POST",
                                    url : 'adq.php',
                                    data: {password: RePassword.val()},                                     
                                    success: function(e)
                                    {
                                        console.log("successfull");
                                    }
                                });         
                                $( this ).dialog( "close" );
                            }
                        },
                    },
                    close: function() 
                    {
                        allFields.val( "" ).removeClass( "ui-state-error" );
                    }
                });
            });
            </script>
            </head>
            <body>
                <div id="dialog-form" title="Create new password">
                    <p class="validateTips"></p>
                    <form>
                        <fieldset>
                            <label for="password">Password</label>
                            <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all">
                            <label for="RePassword">Re-Password</label>
                            <input type="password" name="RePassword" id="RePassword" class="text ui-widget-content ui-corner-all">
                        </fieldset>
                    </form>
                </div>
            </body>
            </html>

重置密码
正文{字体大小:62.5%;}
标签,输入{显示:块;}
input.text{页边距底部:12px;宽度:95%;填充:.4em;}
字段集{填充:0;边框:0;边距顶部:25px;}
h1{字体大小:1.2em;边距:.6em 0;}
div#用户包含{宽度:350px;边距:20px 0;}
div#用户包含表{边距:1em 0;边框折叠:折叠;宽度:100%;}
div#用户包含表td,div#用户包含表th{边框:1px实心#eee;填充:.6em 10px;文本对齐:左;}
.ui对话框.ui状态错误{填充:.3em;}
.validateIPS{边框:1px实心透明;填充:0.001em;}
.ui对话框标题栏关闭{显示:无!重要;}
$(函数()
{
var password=$(“#password”),RePassword=$(“#RePassword”),allFields=$([])。add(password)。add(RePassword),tips=$(“.validateips”);
函数更新(t)
{
text(t).addClass(“ui状态突出显示”);
setTimeout(函数()
{
removeClass(“ui状态突出显示”,1500);
}, 500 );
}
函数校验长度(o、n、最小值、最大值)
{
var pass=password.val();
var repass=RePassword.val();
如果(o.val().length>max | | o.val().length

密码 重新输入密码

有关更多详细信息,请发表评论。

看起来您在使用ajax时忘记将收到的响应添加到网页。表单已提交,但您在网页中看不到更改,因为您实际上没有指定应如何处理数据。您可以使用
$(#elementID).html(html)
将元素的内部html设置为接收到的数据,假设
elementID
是要将数据放置在其中的元素ID,
html
是从ajax接收到的数据

示例

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    var_dump($_REQUEST['password']);
}

/*if($_REQUEST['data'])
{
    $password=$_REQUEST['data'];   

    var_dump($password);
 die;
}*/
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Reset Password</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<style>
body { font-size: 62.5%; }
label, input { display:block; }
input.text { margin-bottom:12px; width:95%; padding: .4em; }
fieldset { padding:0; border:0; margin-top:25px; }
h1 { font-size: 1.2em; margin: .6em 0; }
div#users-contain { width: 350px; margin: 20px 0; }
div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
.ui-dialog .ui-state-error { padding: .3em; }
.validateTips { border: 1px solid transparent; padding: 0.001em; }
.ui-dialog-titlebar-close {display:none !important;}
</style>
<script>
$(function() 
{
    var password = $( "#password" ), RePassword = $( "#RePassword" ), allFields = $( [] ).add(password).add(RePassword ),tips = $( ".validateTips" );
    function updateTips( t ) 
    {
        tips.text( t ).addClass( "ui-state-highlight" );
        setTimeout(function() 
        {
            tips.removeClass( "ui-state-highlight", 1500 );
        }, 500 );
    }
    function checkLength( o, n, min, max ) 
    {
        var pass=password.val();
        var repass=RePassword.val();
        if ( o.val().length > max || o.val().length < min ) 
        {
            o.addClass( "ui-state-error" );
            updateTips( "Length of " + n + " must be between " + min + " and " + max + "." );
            return false;
        }
        else if(pass != repass)
        {
            o.addClass( "ui-state-error" );
            updateTips( "password not match." );
            return false;
        }
        else 
        {
            return true;
        }
    }
    function checkRegexp( o, regexp, n ) 
    {
        if ( !( regexp.test( o.val() ) ) ) 
        {
            o.addClass( "ui-state-error" );
            updateTips( n );
            return false;
        } 
        else 
        {
            return true;
        }
    }
    $( "#dialog-form" ).dialog(
    {
        closeOnEscape: false,
        autoOpen: true,
        height: 250,
        width: 300,
        modal: true,
        buttons: {
            "submit": function(e) {
                var bValid = true;
                allFields.removeClass( "ui-state-error" );
                bValid = bValid && checkLength( password, "password", 8, 16 );
                bValid = bValid && checkLength( RePassword, "RePassword", 8, 16 );

                if ( bValid ) {

                e.preventDefault();
                    $.ajax({
                        type: "POST",
                        url : 'adq.php',
                        data: {password: RePassword.val()},                                     
                        success: function(e)
                        {
                           $("#dialog-form").html(e); 
                           // console.log("successfull");
                        }
                    });         
                    $( this ).dialog( "close" );
                }
            },
        },
        close: function() 
        {
            allFields.val( "" ).removeClass( "ui-state-error" );
        }
    });
});
</script>
</head>
<body>
    <div id="dialog-form" title="Create new password">
        <p class="validateTips"></p>
        <form>
            <fieldset>
                <label for="password">Password</label>
                <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all">
                <label for="RePassword">Re-Password</label>
                <input type="password" name="RePassword" id="RePassword" class="text ui-widget-content ui-corner-all">
            </fieldset>
        </form>
    </div>
</body>
</html>    
假设存在一个名为adq.php的文件,ID
dialog form
的元素是要将其内部HTML更改为从ajax接收的HTML的元素,并且要提交的数据是
RePassword.val()

PHP文件的完整内容

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    var_dump($_REQUEST['password']);
}

/*if($_REQUEST['data'])
{
    $password=$_REQUEST['data'];   

    var_dump($password);
 die;
}*/
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Reset Password</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<style>
body { font-size: 62.5%; }
label, input { display:block; }
input.text { margin-bottom:12px; width:95%; padding: .4em; }
fieldset { padding:0; border:0; margin-top:25px; }
h1 { font-size: 1.2em; margin: .6em 0; }
div#users-contain { width: 350px; margin: 20px 0; }
div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
.ui-dialog .ui-state-error { padding: .3em; }
.validateTips { border: 1px solid transparent; padding: 0.001em; }
.ui-dialog-titlebar-close {display:none !important;}
</style>
<script>
$(function() 
{
    var password = $( "#password" ), RePassword = $( "#RePassword" ), allFields = $( [] ).add(password).add(RePassword ),tips = $( ".validateTips" );
    function updateTips( t ) 
    {
        tips.text( t ).addClass( "ui-state-highlight" );
        setTimeout(function() 
        {
            tips.removeClass( "ui-state-highlight", 1500 );
        }, 500 );
    }
    function checkLength( o, n, min, max ) 
    {
        var pass=password.val();
        var repass=RePassword.val();
        if ( o.val().length > max || o.val().length < min ) 
        {
            o.addClass( "ui-state-error" );
            updateTips( "Length of " + n + " must be between " + min + " and " + max + "." );
            return false;
        }
        else if(pass != repass)
        {
            o.addClass( "ui-state-error" );
            updateTips( "password not match." );
            return false;
        }
        else 
        {
            return true;
        }
    }
    function checkRegexp( o, regexp, n ) 
    {
        if ( !( regexp.test( o.val() ) ) ) 
        {
            o.addClass( "ui-state-error" );
            updateTips( n );
            return false;
        } 
        else 
        {
            return true;
        }
    }
    $( "#dialog-form" ).dialog(
    {
        closeOnEscape: false,
        autoOpen: true,
        height: 250,
        width: 300,
        modal: true,
        buttons: {
            "submit": function(e) {
                var bValid = true;
                allFields.removeClass( "ui-state-error" );
                bValid = bValid && checkLength( password, "password", 8, 16 );
                bValid = bValid && checkLength( RePassword, "RePassword", 8, 16 );

                if ( bValid ) {

                e.preventDefault();
                    $.ajax({
                        type: "POST",
                        url : 'adq.php',
                        data: {password: RePassword.val()},                                     
                        success: function(e)
                        {
                           $("#dialog-form").html(e); 
                           // console.log("successfull");
                        }
                    });         
                    $( this ).dialog( "close" );
                }
            },
        },
        close: function() 
        {
            allFields.val( "" ).removeClass( "ui-state-error" );
        }
    });
});
</script>
</head>
<body>
    <div id="dialog-form" title="Create new password">
        <p class="validateTips"></p>
        <form>
            <fieldset>
                <label for="password">Password</label>
                <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all">
                <label for="RePassword">Re-Password</label>
                <input type="password" name="RePassword" id="RePassword" class="text ui-widget-content ui-corner-all">
            </fieldset>
        </form>
    </div>
</body>
</html>    

重置密码
正文{fon