views:

338

answers:

3

Hi,

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

A: 

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?

Greg
Actually i dont knew the fieldname Doj in my controller.So i am sending both the fieldname and its value and want to save both of them in the Table.
Aruna
A: 

Nope, your $_POST variable won't solve anything:D. And even you can't use $_POST in cakephp. I'm also in trouble with this:((.

wanting252
A: 
PaulANormanNZ