我在这里有这些规则:
ducationStartYear: {
validators: {
numeric: {
message: 'The year must be numeric'
},
stringLength: {
min: 4,
max: 4,
message: 'The year must be exact 4 characters long'
}
}
},
EducationEndYear: {
validators: {
numeric: {
message: 'The year must be numeric'
},
stringLength: {
min: 4,
max: 4,
message: 'The year must be exact 4 characters long'
}
}
},
QualificationMonth: {
validators: {
numeric: {
message: 'The month must be numeric'
},
stringLength: {
min: 2,
max: 2,
message: 'month year must be exact 2 numbers long'
}
}
},
QualificationYear: {
validators: {
numeric: {
message: 'The year must be numeric'
},
stringLength: {
min: 4,
max: 4,
message: 'The year must be exact 4 numbers long'
}
}
},
JobStartDate: {
validators: {
date: {
format: 'DD/MM/YYYY',
max: 'JobEndDate',
message: 'The date is not valid'
}
}
},
JobEndDate: {
validators: {
date: {
format: 'DD/MM/YYYY',
min: 'JobStartDate',
message: 'The date is not valid'
}
}
},
字段集:
<fieldset class="form-group">
<label for="Surname">Month / Year</label>
<div class="input-group">
<?php echo "<input type='text' name='QualificationMonth' class='form-control' placeholder=''value=".$Submission['QualificationMonth'].">" ;?>
<span class="input-group-addon">-</span>
<?php echo "<input type='text' name='QualificationYear' class='form-control' placeholder=''value=".$Submission['QualificationYear'].">" ;?>
</div>
</fieldset>
正如您所看到的,我没有将它们设置为必需。但如果留空则验证器会发出警报。如果他们留空,我希望验证器跳过这些字段。但是,如果用户键入内容以查看输入。怎么可能?
编辑: 我有点深入,真正的问题是,当我使用相同的表单将记录插入数据库时,如果文本框为空,它会向数据库发送值0。 我使用相同的表单将细节提取回表单并允许修改。当我在表单上获取插入的详细信息时,这些特定的文本框显示为0。这是当警告报警时。
所以问题在于在数据库中创建行。
解决:我只是输入一个if语句使''变量为NULL,所以当我将详细信息提取回表单时,该字段为空且不为0.
答案 0 :(得分:0)
解决:我只是发表了一个if语句来制作&#39;&#39;变量为NULL,因此当我将详细信息提取回表单时,该字段为空且不为0.