Welcome Guest, Not a member yet? Register   Sign In
Form validation config & dynamic

(This post was last modified: 03-17-2015, 12:03 PM by BABYpanda. Edit Reason: added )


I am trying to achieve something with the Form Validation in CI 2.2.

The code I am using is for the validation is:
PHP Code:

$this->setConfigValidations($page); // $page is tickets in this case
if(!$this->form_validation->run('form_tickets')) {
// Probably going to add log_message() here.

Then the config file 'form_validation.php':
PHP Code:
<?php ┬áif(!defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'form_tickets' => array(
'field' => 'submitData',
'label' => 'selectTickets',
'rules' => 'trim|required|max_amount|min_amount'

And here a custom function which is also been called in the first code snippet:
PHP Code:
private function setConfigValidations($page) {
$page) {
$tickets $this->config->item('tb_tickets');
array_keys($tickets) as $ticket) {
$this->form_validation->set_rules($this->config->item('tb_tickets_name_form_prefix').$ticket'lang:'.$tickets[$ticket]['name'], 'trim|required|is_ticket|minimum|maximum');

As you can see, I am trying to get one bit loaded using a config, and some fields must be dynamically added since they are retrieved in the config.

But somehow, I am unable to achieve this. Is it somehow possible to load certain validations in a config and others dynamically?

Thanks in advance.

Kindest regards,

Messages In This Thread
Form validation config & dynamic - by BABYpanda - 03-17-2015, 12:03 PM

Theme © iAndrew 2016 - Forum software by © MyBB