php – 肯定是一个愚蠢的错误,但我看不到它
作者:互联网
我有一个表格(大大简化):
<form action='http://example.com/' method='post' name='event_form'>
<input type='text' name='foo' value='3'/>
<input type='submit' name='event_submit' value='Edit'/>
</form>
我有一个类“EventForm”来处理表单.主要方法,process()如下所示:
public function process($submitname=false){
$success=false;
if ($submitname && isset($_POST[$submitname])){ //PROBLEM: isset($_POST[$submitname] is always FALSE for some reason
if($success=$this->ruler->validate()){//check that dependancies are honoured and data types are correct
if($success=$this->map_fields()){//divide input data into Event, Schedule_Element and Temporal_Expression(s)
$success=$this->eventholder->save();
}
}
} else {//get the record from the db based on event_id or schedule_element_id
foreach($this->gets as $var){//list of acceptable $_GET keys
if(isset($_GET[$var])){
if($success= $this->__set($var,$_GET[$var])) break;
}
}
}
$this->action=(empty($this->eventholder->event_id))? ADD : EDIT;
return $success;
}
提交表单时,会发生以下情况:$form-> process(‘event_submit’);但是出于某种原因,isset($_ POST [‘event_submit’])总是计算为FALSE.谁能明白为什么?
ETA:在完成建议后,似乎JQuery.validate()对表单提交产生了意想不到的影响.除提交按钮外,所有字段都已提交.这似乎是这个JQuery的错:
$("form[name='event_form']").validate({
submitHandler: function(form) {
form.submit();
}
}};
有关如何确保提交按钮值的任何想法?
解决方法:
将您的JQuery更改为:
$("form[name='event_form']").validate({
submitHandler: function(form) {
$("form[name='event_form'] input[name='event_submit']").click()
}
}};
标签:html,php,syntax,forms,jquery-validate 来源: https://codeday.me/bug/20190827/1740946.html