0
JQuery의 Form Plugin을 사용하고 있습니다 .. Form Plugin의 js 파일을 추가했습니다. 내 code..beforeSubmit 내가 다음에 시도 내 serverside..I에이 값을 게시 할,하지만 작동하지 올바르게 실제 양식의 내용을 경고에 JQuery Form Plugin to cakephp 컨트롤러로 폼 데이터를 POsting
이미 한 형태입니다 ...내 코드 이다
<?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.');
}
그리고 내 CakePHP의 컨트롤러에서
<?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;
}
}
가 나중에 내가 쿼리 문자열의 eg..My 출력을위한 사실 당신이주고있는 URL .. 와 시도는 = POST 및 이름 1 = 값 1 & NAME2 = 을 값 2를 _method됩니다 그러나 이제 _method = POST는 에코입니다 ... – useranon