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

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

Hello,

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->load->library('form_validation');

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


Then the config file 'form_validation.php':
PHP Code:
<?php  if(!defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
    
'form_tickets' => array(
        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) {
    switch(
$page) {
        case 
'tickets':
            
$tickets $this->config->item('tb_tickets');
            
            foreach(
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');
            }
            
            break;
        default:
            break;
    }


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,
Reno
Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB