我在 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
}
如何从此查询字符串中获取各个数据,以便将其保存到我的数据库中。请建议我..