• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MY_Form_validation method not called on empty string?

#1
[eluser]Unknown[/eluser]
I have extended the form validation to include some extra methods. One of them needs to check if 2 inputs are not empty together, however the method never gets called if the input is empty:

application/libraries/MY_Form_validation.php:

Code:
class MY_Form_validation extends CI_Form_validation {

public function __construct($config = array())
{
  log_message('debug', 'MY_Form_validation loaded<<<');
  parent::__construct($config);
}

public function lat_longs($str)
{
  echo "lat_longs called";
  var_dump($this->CI->input->post('map_lat'));
  var_dump($str);
  return FALSE;
}

application/language/english/form_validation_lang.php:

Code:
$lang['lat_longs'] = "Some error message here.";

application/config/form_valiation.php

Code:
'venues' => array(
  array(
   'field' => 'map_lat',
   'label' => 'Latitude',
   'rules' => 'trim|htmlspecialchars|lat_longs|numeric|xss_clean'
  ),
  array(
   'field' => 'map_lng',
   'label' => 'Longitude',
   'rules' => 'trim|htmlspecialchars|lat_longs|numeric|xss_clean'
  )
),

in the view file:
Code:
&lt;?php echo form_error('map_lat'); ?&gt;

The lat_longs() method never seems to get called if the $_POST['map_lat'] or $_POST['map_lng'] is empty...

Any ideas?

#2
[eluser]Unknown[/eluser]
Change it to use a callback function instead now it works.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.