1

我在 FormBuilder 的应用程序中使用 CakePhp 和 jQuery。我有这样的形式

<form action="/cake_1.2.1.8004/index.php/results/submit1" method="post"
                                                          id="ResultSubmit1Form">
    <fieldset style="display: none;">
        <input type="hidden" value="POST" name="_method"/>     
    </fieldset>

    <div class="input text">
        <label for="1">Doj</label>
        <input type="text" value="" style="width: 300px;" id="1" name="Doj"/>
    </div>

    <div class="input text">
        <label for="2">Name</label>
        <input type="text" value="" style="width: 300px;" id="2" name="Name"/>
    </div>
    <div class="input textarea">
        <label for="3">Address</label>
        <textarea style="height: 300px;" id="3" rows="6" cols="30" name="Address"/>
    </div>
    <div class="input text">
        <label for="4">Age</label>
        <input type="text" value="" style="width: 200px;" id="4" name="Age"/>
    </div>
    <br/><br/>
    <div class="submit">
        <input type="submit" value="submit"/>
    </div>
</form>

我想获取表单中输入的所有值。

使用 jQuery Form 插件,我使用以下代码检索值,例如

<script type="text/javascript">
    $(document).ready(function(){
        $("#submit").eq(0).click(function (){

            var serializedFormStr = $("#ResultSubmit1Form :input[value]").serialize();  
            alert(serializedFormStr);
            $.ajax({
                type: "POST",
                url: "http://localhost/cake_1.2.1.8004/index.php/results/submit1",
                data: serializedFormStr,
                success: function(msg){
                    alert( "Data Saved: " + msg);
                }//success
            });//ajax
        });
    });//ready
</script>   

节目alert(serializedFormStr);

        _method=POST&Doj=07%2F09%2F2009&Name=aruna&Address=xyz&Age=22 

我在我的 Cakephp 控制器中检索到的相同

   function submit1()
   {
       echo "In controller  ".http_build_query($_POST);//echoes correctly
   }

如何从此查询字符串中获取各个数据,以便将其保存到我的数据库中。请建议我..

4

2 回答 2

1

我对此有疑问,发现 http_build_query 有三个可用参数“自 5.1.2 添加了 arg_separator 参数。”(本地 Ms-windows 文件:mk:@MSITStore:D:\Reference\oq\php\php_manual.chm ::/res/function.http-build-query.html 在网络上为http://php.net/manual/en/function.http-build-query.php

当我执行 $_POST var 转储时,我的第二个和第三个变量名称出现为 amp;rowsPerPage 和 amp;startNumber 前导 & 已被吃掉

无论出于何种原因,我必须在我正在做的事情中这样做,

$postdata = http_build_query(
   array(
    'whereRequest' => $whereRequest,
    'rowsPerPage' => '20',
'startNumber' => '0'
   )
   ,'','&'
);

在我的情况下不需要第二个参数(numeric_prefix - 它是一个字符串),我明确地将 arg_separator 参数设置为“&”,我确信这是默认值。

帮助文件示例显示&ampamp;为一个选项,但不起作用,

在我将 arg_separator 参数显式设置为:'&' 之后,无论出于何种原因,一切都正常

于 2010-09-25T07:42:21.930 回答
0

没听懂……你打电话http_build_query干嘛?你只需要确定地看$_POST['Doj']

您可以像这样循环 $_POST:

foreach ($_POST as $key => $value)
    echo 'The value of ' . $key . ' is ' . $value;

或者获取所有键的数组:

$keys = array_keys($_POST);
// $keys is now array('Doj', 'Name', 'Address', 'Age')

这有帮助吗?

于 2009-07-01T09:06:17.783 回答