我试图在表单中添加验证,这个输入给我带来了麻烦。我喜欢它做的是在一个新的表单上输入下拉列表将被设置为选择($ text_select),那将是value =“”然后如果他们尝试提交验证规则将生效。目前没有发生这种情况,我不知道为什么 VIEW:
[使用$ text_select和验证的工作输入]
<div class="col-sm-5 col-sm-push-1 form-group required">
<label class="control-label" ><?php echo $entry_owner; ?></label>
<select name="campaign_owner" id="campaign_owner" >
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($users as $user) { ?>
<option value="<?php echo $user['username']; ?>" <?php echo ($campaign_owner == $user['username']) ? 'selected' : ''; ?>><?php echo $user['username']; ?></option>
<?php } ?>
</select>
<?php if ($error_campaign_owner) { ?>
<div class="text-danger"><?php echo $error_campaign_owner; ?></div>
<?php } ?>
</div>
[乱搞输入]
<div class="col-sm-5 col-sm-push-1 form-group required">
<label class="control-label" for="input-active"><?php echo $entry_active; ?></label>
<select name="campaign_active" id="input-active" class="form-control">
<option value=""><?php echo $text_select; ?></option>
<?php if ($campaign_active ) { ?>
<option value="1" selected="selected"><?php echo $text_yes; ?></option>
<option value="0"><?php echo $text_no; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_yes; ?></option>
<option value="0" selected="selected"><?php echo $text_no; ?></option>
<?php } ?>
</select>
<?php if (isset($error_campaign_active)) { ?>
<label class="text-danger"><?php echo $error_campaign_active; ?></label>
<?php } ?>
</div>
控制器:
[表格功能]
if (isset($this->error['campaign_active'])) {
$data['error_campaign_active'] = $this->error['campaign_active'];
} else {
$data['error_campaign_active'] = '';
}
[验证功能]
if (($this->request->post['campaign_active']) == ''){
$this->error['campaign_active'] = $this->language->get('error_campaign_active');
}