HTML查看表单
<div class="form-group">
<div class="col-lg-4">
<input type="text" name="keywords[]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[]'); ?>" placeholder="Tag or Keyword" />
</div>
</div>
在我的控制器中
$this->form_validation->set_rules('keywords[]', 'Keyword or Tags', 'xss_clean|alpha_dash');
实际问题,
关键字数组的所有上述输入文本都不是必需的(控制器中不需要应用规则),但如果用户输入alpha_dash
以外的其他内容,则Codeigniter应仅显示该字段的验证错误。它不应该显示空白字段的错误。
如果我写回调,我该如何管理return FALSE and error message for particular text box
?
我怎样才能做到这一点?有什么建议? 感谢
答案 0 :(得分:0)
我认为通过为关键字添加索引,您可以做到这一点。但您需要为每种输入类型指定单独的验证。
<div class="form-group">
<div class="col-lg-4">
<input type="text" name="keywords[0]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[0]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[1]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[1]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[2]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[2]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[3]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[3]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[4]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[4]'); ?>" placeholder="Tag or Keyword" />
</div>
<div class="col-lg-4">
<input type="text" name="keywords[5]" class="form-control input-sm" tagchecker="alphanumeric" value="<?php echo set_value('keywords[5]'); ?>" placeholder="Tag or Keyword" />
</div>
</div>
在控制器中。
$this->form_validation->set_rules('keywords[0]', 'Keyword or Tags', 'xss_clean|alpha_dash');
$this->form_validation->set_rules('keywords[1]', 'Keyword or Tags', 'xss_clean|alpha_dash');
$this->form_validation->set_rules('keywords[2]', 'Keyword or Tags', 'xss_clean|alpha_dash');
$this->form_validation->set_rules('keywords[3]', 'Keyword or Tags', 'xss_clean|alpha_dash');
$this->form_validation->set_rules('keywords[4]', 'Keyword or Tags', 'xss_clean|alpha_dash');
$this->form_validation->set_rules('keywords[5]', 'Keyword or Tags', 'xss_clean|alpha_dash');
我认为它会解决你的问题。