Hi!
I am using JQuery's Form Plugin.
How can I get the posted value in the cakephp controller?
My code is like this:
<?php echo $form->create('Result',array('action'=>'submit'));?>
//some input text fields,texarea fields
<?php echo $form->end('submit');?>
<script>
$(document).ready(function(){
var options = {
beforeSubmit: showRequest, // pre-submit callback
success: showResponse, // post-submit callback
url: "http://localhost/cake_1.2.1.8004/index.php/results/submit1",
type: 'POST',
resetForm: true // reset the form after successful submit
};
$('#ResultSubmit1Form').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
});//ready
// pre-submit callback
function showRequest(formData, jqForm, options) {
var queryString = $.param(formData);
alert('About to submit: \n\n' + queryString);
$.ajax({
type: "POST",
url: "http://localhost/cake_1.2.1.8004/index.php/results/submit1",
data: "str="+queryString,
success: function(msg){
alert( "Data Saved: " + msg);
}
});
return true;
}
// post-submit callback
function showResponse(responseText, statusText) {
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
</script>
And in my CakePHP controller:
<?php
class ResultsController extends AppController
{
var $name = 'Results';
var $helpers=array('Html','Ajax','Javascript','Form');
var $components = array( 'RequestHandler','Email');
var $uses=array('Form','User','Attribute','Result');
function submit($id = null) {
$str=$_POST['str'];
echo "POSTED value ".$str;
}
}
it's displaying only _method=POST
instead of _method=POST&name=x&age=22
.
But if i used $_POST['Name'];
(where Name
is the name
attribute of the input field1), it's displaying the x that I typed in the input field1.
How do I get what I want?