Welcome Guest, Not a member yet? Register   Sign In
yet more form validation 1.7
#31

[eluser]soupdragon[/eluser]
not a problem because that now works with my rules in the controller but still refuses to work when they are in the config file.

And a pure btw in the documentation
here
- surely this is wrong and should read 'member/signup' => array(
not 'member/signup' = array(

Code:
In your validation config file, you will name your rule group member/signup:

$config = array(
           'member/signup' = array(
                                    array(
                                            'field' => 'username',
                                            'label' => 'Username',
                                            'rules' => 'required'
                                         )
#32

[eluser]soupdragon[/eluser]
whats an easy way to output through codeigniter my validation rule file

because even changing the form_validation.php file to its simplist from

Code:
$config = array(
              
                 'seller/seller_reg' => array(
                                    array(
                                            'field' => 'seller_name',
                                            'label' => 'lang:seller_name',
                                            'rules' => 'trim|required|min_length[4]|max_length[12]|xss_clean|callback_username_check'
                                         ),
                                    array(
                                            'field' => 'seller_password',
                                            'label' => 'lang:seller_password',
                                            'rules' => 'trim|required|matches[passconf]|xss_clean'
                                         ),
                                    array(
                                            'field' => 'passconf',
                                            'label' => 'lang:passconf',
                                            'rules' => 'trim|required|xss_clean'
                                         ),
                                    array(
                                            'field' => 'firmname',
                                            'label' => 'lang:firmname',
                                            'rules' => 'trim|required|xss_clean'
                                         ),
                                    array(
                                            'field' => 'firstname',
                                            'label' => 'lang:firstname',
                                            'rules' => 'trim|required|xss_clean'
                                         ),
                                    array(
                                            'field' => 'lastname',
                                            'label' => 'lang:lastname',
                                            'rules' => 'trim|required|xss_clean'
                                         ),
                                    array(
                                            'field' => 'street',
                                            'label' => 'lang:street',
                                            'rules' => 'trim|required|xss_clean'
                                         ),
                                    array(
                                            'field' => 'plz',
                                            'label' => 'lang:plz',
                                            'rules' => 'trim|required|xss_clean'
                                         ),
                                    array(
                                            'field' => 'city',
                                            'label' => 'lang:city',
                                            'rules' => 'trim|required|xss_clean'
                                         ),
                                    array(
                                            'field' => 'email',
                                            'label' => 'lang:email',
                                            'rules' => 'trim|required|valid_email|xss_clean'
                                         ),
                                    array(
                                            'field' => 'tel',
                                            'label' => 'lang:tel',
                                            'rules' => 'trim|required|xss_clean'
                                         ),
                                    array(
                                            'field' => 'handy',
                                            'label' => 'lang:handy',
                                            'rules' => 'trim|xss_clean'
                                         ),
                                    array(
                                            'field' => 'type',
                                            'label' => 'lang:type',
                                            'rules' => 'trim|xss_clean'
                                         )
                                    )

                );

make no difference which seems to mean it is not being called
#33

[eluser]TheFuzzy0ne[/eluser]
You're right. That would result in a parse error as you're trying to assign an array to a string.
#34

[eluser]TheFuzzy0ne[/eluser]
Code:
echo file_get_contents(APPPATH . 'config/form_validation.php');

Although I doubt this will help in any way. Are you sure you've got the opening PHP tag at the top of the page?

Also, please check your log for the following message: Unable to find validation rules

Upon further examination, I can't see where the form_validation class automatically loads the config file, so it might be worth adding a:
Code:
$this->load->config('form_validation');

in there to see.

You could also add a:
Code:
log_message('debug', 'My validation rules have been loaded');
to the top of the file, and check for it in the log.
#35

[eluser]soupdragon[/eluser]
:-) yes .....

Code:
<?
# this is mine - global form validation rules
# new in CI 1.7

ok so its definately finds the form_validation and can echo it out, its just not calling / using it !

so back to my controller - like this now
Code:
<?
class seller extends Controller {

        var $ci;
    function __construct()
    {
    parent::Controller();
    $this->load->library('form_validation');
    $this->output->enable_profiler();
    }

     # -------------------------------------------------------------------------    
     function seller_reg()
     {

        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css');
        $data['css'] = $this->css;
        $data['base'] = $this->base;
        $this->load->library('session');

        $data['webTitle'] = ' Seller werden';
        $data['extraHeadContent'][] = '<link rel="stylesheet" type="text/css" href="./css/seller.css" media="screen"/>';
        $data['page'] =  'seller/seller_reg';
        
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        
        #Dropdown attributes
        $extras['type'] = array('1' => 'privat', '2' => 'firma');


        if(is_numeric($this->session->userdata('sellerid'))) {
            # $data['form'] = $this->createForm('selleredit', $extras);
            $this->seller_edit();
        } else {
            $data['form'] = $this->createForm('index', $extras);    
        }
    if ($this->form_validation->run() != FALSE)
        {            
        # pass values to insert
        $data['seller'] = $this->createForm('insert');
        # end form creation test
            # all validated so go dump in db - in a model
            $this->load->model('sellers');
            $sid = $this->sellers->insertnewseller($data['seller']);
            if((is_numeric($sid))&&($sid > 0)) {

             $data['seller_name'] = $data['seller']['seller_name'];
             $this->session->set_userdata('seller_name',  $data['seller']['seller_name']);

                $this->load->model('email_model');

                $this->email_model->send('register', $_POST);
                $data['page'] =  'seller/toconfirm';

            } else {
                $data['page'] =  'start/contact';
                $data['error'] ='Ooops somethings gone wrong';

            }
        }
        $this->load->view('container' , $data);
     }

}
?>
#36

[eluser]soupdragon[/eluser]
Have added this to the controller - no difference
$this->load->config('form_validation');
in there to see.

where do you want this ->log_message('debug', 'My validation rules have been loaded');
#37

[eluser]TheFuzzy0ne[/eluser]
At the top of config/form_validation.php. It will let you know whether or not the file is being loaded.
#38

[eluser]soupdragon[/eluser]
yes they are being
#39

[eluser]TheFuzzy0ne[/eluser]
Let's see where it's failing:

./system/application/libraries/MY_form_validation.php
Code:
<?php

class MY_Form_validation extends CI_Form_validation {

    function run($group = '')
    {
        // Do we even have any data to process?  Mm?
        if (count($_POST) == 0)
        {
            log_message('debug', 'No post data to process');
            return FALSE;
        }
        
        // Does the _field_data array containing the validation rules exist?
        // If not, we look to see if they were assigned via a config file
        if (count($this->_field_data) == 0)
        {
            log_message('debug', 'No data supploed via set rules, so checking config file');
            // No validation rules?  We're done...
            if (count($this->_config_rules) == 0)
            {
                log_message('debug', "Can't find any validation rules");
                return FALSE;
            }
            
            // Is there a validation rule for the particular URI being accessed?
            $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group;
            
            if ($uri != '' AND isset($this->_config_rules[$uri]))
            {
                log_message('debug', 'Loading validation rule group: ' . $uri);
                $this->set_rules($this->_config_rules[$uri]);
            }
            else
            {
                log_message('debug', 'No groups found in the array, so just using the array as-is');
                $this->set_rules($this->_config_rules);
            }
    
            // We're we able to set the rules correctly?
            if (count($this->_field_data) == 0)
            {
                log_message('debug', "Unable to find validation rules");
                return FALSE;
            }
        }
    
        // Load the language file containing error messages
        $this->CI->lang->load('form_validation');
                            
        // Cycle through the rules for each field, match the
        // corresponding $_POST item and test for errors
        log_message('debug', 'running validation');
        foreach ($this->_field_data as $field => $row)
        {        
            // Fetch the data from the corresponding $_POST array and cache it in the _field_data array.
            // Depending on whether the field name is an array or a string will determine where we get it from.
            
            if ($row['is_array'] == TRUE)
            {
                $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']);
            }
            else
            {
                if (isset($_POST[$field]) AND $_POST[$field] != "")
                {
                    $this->_field_data[$field]['postdata'] = $_POST[$field];
                }
            }
        
            $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']);        
        }

        // Did we end up with any errors?
        $total_errors = count($this->_error_array);

        if ($total_errors > 0)
        {
            log_message('debug', "D'oh!!");
            $this->_safe_form_data = TRUE;
        }

        // Now we need to re-set the POST data with the new, processed data
        $this->_reset_post_array();
        
        // No errors, validation passes!
        if ($total_errors == 0)
        {
            log_message('debug', 'Woohoo!');
            return TRUE;
        }

        // Validation fails
        return FALSE;
    }

}

watch the log file for information. It should be self-explanatory.
#40

[eluser]soupdragon[/eluser]
where/how do you want me to run that from?




Theme © iAndrew 2016 - Forum software by © MyBB