我可以解释 http_build_query($_POST) 以便将其保存到 CakePHP 中的数据库吗?

发布于 2024-07-26 01:39:55 字数 2356 浏览 3 评论 0原文

我在 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
   }

如何从该查询字符串中获取各个数据我可以将它保存在我的数据库中。 请推荐我..

I am using CakePhp and jQuery in my application of FormBuilder.
I am having form as like

<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>

I want to get all the values entered in the form.

Using jQuery Form plugin i have used the following code to retrieve the values like

<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>   

The alert(serializedFormStr); shows as

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

same I retrieved in my Cakephp controller as

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

How can I get the individual datas from this query string so that I can save it my database.
Please suggest me..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初熏 2024-08-02 01:39:55

我遇到了这个问题,发现 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 参数设置为“&”,这是我我确定,无论如何都是默认的。

帮助文件示例指示 & 作为一个选项,但这不起作用,

出于某种原因,在我将 arg_separator 参数显式设置为“&”后一切正常

I had a problem with this and discovered that http_build_query has three arguments available "since 5.1.2 The arg_separator parameter was added. " ( local Ms-windows file: mk:@MSITStore:D:\Reference\o-q\php\php_manual.chm::/res/function.http-build-query.html on web as http://php.net/manual/en/function.http-build-query.php )

When I did a $_POST var dump my second and third varibale names were coming out as amp;rowsPerPage and amp;startNumber the leading & had been eaten

For whatever reason I had to do this in what I was doing,

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

the second argument (numeric_prefix - which is a string) was not needed in my case, and I explicitly set arg_separator parameter to '&', which was I am sure, the default any way.

The help file examples indicated &amp; as an option but that did not work,

For what ever reason everything went ok after I explicitly set the arg_separator parameter to: '&'

爱给你人给你 2024-08-02 01:39:55

我不明白...为什么要调用 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')

这有帮助吗?

I don't get it... why are you calling http_build_query? You just need to look at $_POST['Doj'] surely.

You can loop through $_POST like this:

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

Or get an array of all the keys:

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

Does that help?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文