php - Codeigniter input type text array validation -


html view form

<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> 

in controller

$this->form_validation->set_rules('keywords[]', 'keyword or tags', 'xss_clean|alpha_dash'); 

actual problem, above input text's keywords array not mandatory (no required rule applied in controller), if user enters other alpha_dash, codeigniter should display validation error field only. should not display error blank fields.

if write callback, how can manage return false , error message particular text box?

how can achieve this? suggestions? thanks

i think adding index keywords can think. need specify separate validation each input type.

<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> 

in controller.

$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'); 

i think solve problem.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -