php - Set Rules Not Working CI -
php - Set Rules Not Working CI -
for reason, codeigniter callbacks in hierarchical model–view–controller not working, have my_form_validation library function.
it should throw $error if required or missing.
i renamed image folder , no error showed up. ideas how can create work phone call validate? here's code:
<?php if (!defined('basepath')) exit('no direct script access allowed'); class step_2 extends controller { // controller renamed in my_controller.php public $error = array(); public function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->helper('file'); $this->load->helper('form'); $this->load->library('form_validation'); $this->lang->load('english', 'english'); } public function index() { $this->form_validation->set_rules(phpversion(), 'required|callback_validate'); $this->form_validation->set_rules(ini_get('register_globals'), 'required|callback_validate'); $this->form_validation->set_rules(ini_get('magic_quotes_gpc'), 'required|callback_validate'); $this->form_validation->set_rules(ini_get('file_uploads'), 'required|callback_validate'); $this->form_validation->set_rules(ini_get('session_auto_start'), 'required|callback_validate'); $this->form_validation->set_rules(extension_loaded('mysql'), 'required|callback_validate'); $this->form_validation->set_rules(extension_loaded('mysqli'), 'required|callback_validate'); $this->form_validation->set_rules(extension_loaded('pdo'), 'required|callback_validate'); $this->form_validation->set_rules(extension_loaded('pgsql'), 'required|callback_validate'); $this->form_validation->set_rules(extension_loaded('gd'), 'required|callback_validate'); $this->form_validation->set_rules(extension_loaded('curl'), 'required|callback_validate'); $this->form_validation->set_rules(function_exists('mcrypt_encrypt'), 'required|callback_validate'); $this->form_validation->set_rules(extension_loaded('mbstring'), 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath) . '/admin/config/config.php', 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath) . '/catalog/config/config.php', 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath) . '/admin/cache', 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath) . '/catalog/cache', 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath) . '/admin/logs', 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath). '/catalog/logs', 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath) . '/image', 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath) . '/image/cache', 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath) . '/image/catalog', 'required|callback_validate'); $this->form_validation->set_rules(dirname(fcpath) . '/download', 'required|callback_validate'); if($this->form_validation->run($this)) { redirect('step_3'); } else { if (array_key_exists('warning', $this->error)) { $data['error_warning'] = $this->error['warning']; } else { $data['error_warning'] = ''; } $data['action'] = site_url('step_2'); $data['php_version'] = phpversion(); $data['register_globals'] = ini_get('register_globals'); $data['magic_quotes_gpc'] = ini_get('magic_quotes_gpc'); $data['file_uploads'] = ini_get('file_uploads'); $data['session_auto_start'] = ini_get('session_auto_start'); $data['mysql'] = extension_loaded('mysql'); $data['mysqli'] = extension_loaded('mysqli'); $data['mpdo'] = extension_loaded('pdo'); $data['pgsql'] = extension_loaded('pgsql'); $data['gd'] = extension_loaded('gd'); $data['curl'] = extension_loaded('curl'); $data['mcrypt_encrypt'] = function_exists('mcrypt_encrypt'); $data['zlib'] = extension_loaded('zlib'); $data['iconv'] = function_exists('iconv'); $data['mbstring'] = extension_loaded('mbstring'); $data['config_catalog'] = dirname(fcpath) . '/catalog/config/config.php'; $data['config_admin'] = dirname(fcpath) . '/admin/config/config.php'; $data['admin_cache'] = dirname(fcpath) . '/admin/cache'; $data['catalog_cache'] = dirname(fcpath) . '/catalog/cache'; $data['admin_logs'] = dirname(fcpath) . '/admin/logs'; $data['catalog_logs'] = dirname(fcpath) . '/catalog/logs'; $data['download'] = dirname(fcpath) . '/download'; $data['image'] = dirname(fcpath) . '/image'; $data['image_cache'] = dirname(fcpath) . '/image/cache'; $data['image_data'] = dirname(fcpath) . '/image/catalog'; $data['back'] = site_url("step_1"); $this->load->view('template/step_2', $data); } } public function validate() { if (phpversion() < '5.3') { $this->error['warning'] = 'warning: need utilize php5.3 or above ci project work!'; } if (!ini_get('file_uploads')) { $this->error['warning'] = 'warning: file_uploads needs enabled!'; } if (ini_get('session.auto_start')) { $this->error['warning'] = 'warning: ci project not work session.auto_start enabled!'; } if (!array_filter(array('mysqli', 'pdo', 'pgsql'), 'extension_loaded')) { $this->error['warning'] = 'warning: database extension needs loaded in th php.ini ci project work!'; } if (!extension_loaded('gd')) { $this->error['warning'] = 'warning: gd extension needs loaded ci project work!'; } if (!extension_loaded('curl')) { $this->error['warning'] = 'warning: curl extension needs loaded ci project work!'; } if (!function_exists('mcrypt_encrypt')) { $this->error['warning'] = 'warning: mcrypt extension needs loaded ci project work!'; } if (!extension_loaded('zlib')) { $this->error['warning'] = 'warning: zlib extension needs loaded ci project work!'; } if (!function_exists('iconv')) { if (!extension_loaded('mbstring')) { $this->error['warning'] = 'warning: mbstring extension needs loaded ci project work!'; } } if (!file_exists(dirname(fcpath) . '/admin/config/config.php')) { $this->error['warning'] = 'warning: admin/config.php not exist. need rename admin/config-dist.php admin/config.php!'; } elseif (!is_writable(dirname(fcpath) . '/admin/config/config.php')) { $this->error['warning'] = 'warning: admin/config.php needs writable ci project installed!'; } if (!file_exists(dirname(fcpath) . '/catalog/config/config.php')) { $this->error['warning'] = 'warning: config.php not exist. need rename config-dist.php config.php!'; } elseif (!is_writable(dirname(fcpath) . '/catalog/config/config.php')) { $this->error['warning'] = 'warning: config.php needs writable ci project installed!'; } if (!is_writable(dirname(fcpath) . '/admin/cache')) { $this->error['warning'] = 'warning: cache directory needs writable ci project work!'; } if (!is_writable(dirname(fcpath) . '/catalog/cache')) { $this->error['warning'] = 'warning: cache directory needs writable ci project work!'; } if (!is_writable(dirname(fcpath) . '/admin/logs')) { $this->error['warning'] = 'warning: logs directory needs writable ci project work!'; } if (!is_writable(dirname(fcpath). '/catalog/logs')) { $this->error['warning'] = 'warning: logs directory needs writable ci project work!'; } if (!is_writable(dirname(fcpath) . '/image')) { $this->error['warning'] = 'warning: image directory needs writable ci project work!'; } if (!is_writable(dirname(fcpath) . '/image/cache')) { $this->error['warning'] = 'warning: image cache directory needs writable ci project work!'; } if (!is_writable(dirname(fcpath) . '/image/catalog')) { $this->error['warning'] = 'warning: image catalog directory needs writable riwaka website designs ci project work!'; } if (!is_writable(dirname(fcpath) . '/download')) { $this->error['warning'] = 'warning: download directory needs writable ci project work!'; } if (!$this->error) { homecoming true; } else { homecoming false; } } }
$this->form_validation->set_rules('input_name_attribute', 'the name', 'rules|seperated|like|this);
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#validationrules
from user guide:
$this->form_validation->set_rules();
the above function takes 3 parameters input:
the field name - exact name you've given form field.
a "human" name field, inserted error message. example, if field named "user" might give human name of "username". note: if field name stored in language file, please see translating field names.
the validation rules form field.
edit
you should this;
public function index() { if ( $this->validate() ) { echo 'validation passed'; } else { echo 'validation failed!'; } }
your validate function checking wheher have php extensions enabled , libraries loaded, there's no need utilize form_validation this. form validation works form submissions.
php codeigniter
Comments
Post a Comment