Hi, i am using Form plugin of JQuery.. I added the js file of Form plugin.
Already a form is in my code..beforeSubmit alerts the actual form contents correctly,I want to POst this value into my serverside..I tried with the following ,But not working...
My code is
<?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.');
}
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;
}
}