I'm using Codeigniter, and I'm trying to make form_validation work.
Yesterday I started to check some of the forms of my website, using the codeigniter default rules, and for some, using my owns with callbacks. I tested every forms yesterday and it was working, and today, I worked on some other forms, which aren't working, and I wanted to test the one from yesterday and they now don't work too, and I don't understand why.
One of my form :
<form id="form_group_data" name="form_group_data" method="post" class="form-horizontal" action="<?php echo site_url('cms/cms/add')?>">
<p>
<div class="form-body">
<div class="form-group">
<label class="col-md-2 control-label" for="cms"><?php echo lang('nomcms'); ?><span class="required"> * </span></label>
<div class="col-md-4">
<input id="cms" class="form-control" type="text" rows="5" name="cms" required="required" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="telephone"><?php echo lang('phone'); ?><span class="required"> * </span></label>
<div class="col-md-4">
<input id="telephone" class="form-control" placeholder="<?php echo lang('exemple_number'); ?>" type="text" rows="5" name="telephone" required="required" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="email"><?php echo lang('email'); ?><span class="required"> * </span></label>
<div class="col-md-4">
<input id="email" class="form-control" type="text" rows="5" name="email" required="required" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="id_localite"><?php echo lang('localite'); ?><span class="required"> * </span></label>
<div class="col-md-4">
<?php echo form_dropdown('id_localite', $id_localite, null,'class="form-control" required="required"')?>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="id_langue"><?php echo lang('langue'); ?><span class="required"> * </span></label>
<div class="col-md-4">
<?php echo form_dropdown('id_langue', $id_langue, null,'class="form-control" required="required"')?>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2"><?php echo lang('active'); ?></label>
<div class="col-md-9">
<input type="checkbox" checked="checked" name="actif" class="make-switch" data-on-text=" <?php echo lang('actif'); ?> " data-off-text=" <?php echo lang('inactif'); ?> " data-on-color="info" data-off-color="danger">
</div>
</div>
</div>
<input type="submit" value="<?php echo lang('add'); ?>" class="btn blue"/>
<button type="button" class="btn default" onclick="window.location='<?php echo site_url('cms/cms')?>'"><?php echo lang('cancel'); ?></button>
</div>
</p>
</form>
The form validation :
$this->form_validation->set_rules('cms', 'cms', 'trim|required|xss_clean|callback_customAlphaNum');
$this->form_validation->set_rules('telephone', 'telephone', 'trim|required|xss_clean|callback_customNatural|exact_length[12]');
$this->form_validation->set_rules('email', 'email', 'trim|required|xss_clean|valid_email');
$this->form_validation->set_rules('id_localite', 'id_localite', 'trim|required|xss_clean');
$this->form_validation->set_rules('id_langue', 'id_langue', 'trim|required|xss_clean');
// callback function
function customAlphaNum($str)
{
if ( !preg_match('/^[a-z0-9 -]+$/i',$str) )
{
return false;
}
}
function customNatural($str)
{
if ( !preg_match('/^[0-9+]+$/i',$str) )
{
return false;
}
}
// custom error message
$this->form_validation->set_message('customAlphaNum', lang('form_validation_customAlphaNum'));
// custom error message
$this->form_validation->set_message('customNatural', lang('form_validation_customNatural'));
if ($this->form_validation->run() == FALSE)
{
$this->insert();
}
else
{
...
}
Now whatever I write in my fields triggers the error, even if it follows the rule I created. Actually, it triggers every callback I created, but not the default rule from codeigniter (like valid_email, required, etc.) so it is a problem with my callbacks, but yesterday I had no issue. Does anyone know what could cause this issue ?