• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SOLVED - FORM VAL / SESSION, more than one error page two errors out??

#1
[eluser]RJ[/eluser]
Hello,

I have a multi-page form, the controller code is below. Upon success your taken to page two. The problem is if a user makes an error more than once, then the site errors out, and I can not get a successful screen again. In many cases the entire site is down for a period of time, or if I open another browser, I can run through again unless error more than once, then same issue; i'm thinking it might have something to do with how I am handling sessions.. code below your input is gre

I could really use a hand figuring this out if you have any idea.



First we assign dealer to set template skin, then default page.
Code:
function device($dealer = '999', $page = 'personal_information')
    {
        $this->benchmark->mark('code_start');
        // start benchmarking
        
        # Load stuff
        $this->load->helper(array('form'));                    // load helpers
        $this->load->library('form_validation');            // load libraries    
        $this->form_validation->set_error_delimiters('<pre class="alert">', '</pre>');
        $this->load->model('dealer_model','dealer');        // load dealer
        $this->load->model('suw_model', 'suw');                // load suw
        $this->load->model('common_model', 'common');        // load common
        $this->lang->load('suw_main');                        // load language
        
        # Set dealer params
        $this->dealer->set_dealer($dealer);        // passes db info to dealer model for processing
        $this->load->model('Trimtrac_model', 'trimtrac');    
        
        switch($page)
        {
            case "personal_information":
            default:
                $this->page_one();
                break;
            
            case "plan_information":
                $this->page_two();
                break;
        }
                
        // end benchmarking
        $this->benchmark->mark('code_end');
    }

If not errors we add data to a session then proceed to page 2
Code:
function page_one()
    {
        // Set langauge for error messages
        $this->lang->load('form_validation');

        // Validation Check: rules are managed in the config/form_validation.php file
        if ($this->form_validation->run('device') == FALSE)
        {    
            // Build the page
            $page = 'page_one';
            $data['css'] = $this->common->set_css();
            $data['nav'] = $this->suw->navigation($page);
            $data['round_start'] = $this->common->round_start();
            $ctyarr = array();
            $cdata = $this->suw->country_generator($this->dealer->countries,$this->lang->lang());
            $ctyarr['countries'] = $cdata;
            $data['content']    =    $this->load->view('device_one',$ctyarr, TRUE);
            $data['sidebar'] = "Side bar here";
            $data['round_end'] = $this->common->round_end();
            $data['footer'] = "Footer";
            $data['google'] = $this->load->view('google','', TRUE);
            
            // write to template
            $this->template->write('title', '');
            $this->template->write('css', $data['css']);
            $this->template->write('nav', $data['nav']);
            $this->template->write('round_start', $data['round_start']);
            $this->template->write('content', $data['content']);
            $this->template->write('sidebar', $data['sidebar']);
            $this->template->write('round_end', $data['round_end']);
            $this->template->write('footer', $data['footer']);
            $this->template->write('google', $data['google']);
            
            // render page
            $this->template->render();
        }
        else
        {
            // make sure session is empty
            $this->session->sess_destroy();
            // build session
            $session = array(
                        'country' => $this->input->post('country'),
                        'MSISDN' => $this->input->post('MSISDN'),
                        'UNITID' => $this->input->post('UNITID'),
                        'FirstName' => $this->input->post('FirstName'),
                        'LastName' => $this->input->post('LastName'),
                        'M_COMP' => $this->input->post('M_COMP'),
                        'MC_vatnr' => $this->input->post('MC_vatnr'),
                        'StreetShipAddress1' => $this->input->post('StreetShipAddress1'),
                        'CityShip' => $this->input->post('CityShip'),
                        'postcode' => $this->input->post('postcode'),
                        'email' => $this->input->post('email'),
                        'vemail' => $this->input->post('vemail'),
                        'password' => $this->input->post('password'),
                        'vpassword' => $this->input->post('vpassword'),
                        'cartId' => $this->input->post('cartId'),
                        'vcartId' => $this->input->post('vcartId'),
                        'terms' => $this->input->post('terms')
                    );
            // write to session
            $this->session->set_userdata($session);
            // redirect to page two
            redirect('shop/device/'.$this->dealer->dealer.'/plan_information', 'refresh');
        }
    }

#2
[eluser]RJ[/eluser]
First post was too long, here is the code handling page two so far, not much.
Code:
function page_two()
    {
        // Build the page
        $page = 'page_two';
        $data['css']         = $this->common->set_css();
        $data['nav']         = $this->suw->navigation($page);
        $data['round_start']= $this->common->round_start();
        $data['content']    =    $this->load->view('device_two');
        $data['sidebar']     = "Side bar here";
        $data['round_end']     = $this->common->round_end();
        $data['footer']     = "Ouch!  This is my foot...er";
        $data['google']     = $this->load->view('google','', TRUE);
        
        // write to template
        $this->template->write('title', 'Welcome Page Two');
        $this->template->write('css', $data['css']);
        $this->template->write('nav', $data['nav']);
        $this->template->write('round_start', $data['round_start']);
        $this->template->write('content', $data['content']);
        $this->template->write('sidebar', $data['sidebar']);
        $this->template->write('round_end', $data['round_end']);
        $this->template->write('footer', $data['footer']);
        $this->template->write('google', $data['google']);
        // render page
        $this->template->render();
        
        print('Page duce');
    }

#3
[eluser]The Wizard[/eluser]
if i have to use 2 validations or another custom validation and
the check fails (even if the correct required value is entered) i add
a bogus rule with a field that does not exists so the validation fails
OR i reload the form.

maybe that is what you want?

#4
[eluser]RJ[/eluser]
@herrkaleun any chance you could provide an example, not entirely following the logic. thank you

#5
[eluser]The Wizard[/eluser]
Code:
$city_id         = $this->input->post ('city_id');
                $country_code     = $this->input->post ('country_code');
                if ( $this->model_user->Custom_City_Check( $country_code, $city_id ) == FALSE )
                {
                    $_POST['city_id'] = '-1';
                    //$this->form_validation->set_rules( 'dummy',         '',         'required' );
                }                

                //TODO: language
                $this->form_validation->set_rules( 'name',                 'Name',         'required|min_length[3]|max_length[32]' );
                $this->form_validation->set_rules( 'city_id',             'City ID',         'required|is_natural' );
                $this->form_validation->set_rules( 'work',                 'Work',         'required' );
                $this->form_validation->set_rules( 'country_code',         'Country',         'required' );
                
                /**
                    birthday ile ilgili seyler.
                **/
                $this->form_validation->set_rules( 'birthday_d',         'birthday_d', '' );
                $this->form_validation->set_rules( 'birthday_m',         'birthday_m', '' );
                $this->form_validation->set_rules( 'birthday_y',          'birthday_y',        'required' );



                switch ( $this->form_validation->run() )
                {

                    case FALSE :

                        $data['values']['name']             = set_value( 'name' );
                        $data['values']['city_id']          = set_value( 'city_id' );
                        $data['values']['work']             = set_value( 'work' );
                        
                        
                        $data['values']['birthday_d'] = $this->model_user->Dropdown_date ( 'birthday_d', set_value( 'birthday_d' ), 'day', FALSE );
                        $data['values']['birthday_m'] = $this->model_user->Dropdown_date ( 'birthday_m', set_value( 'birthday_m' ), 'month', FALSE );
                        $data['values']['birthday_y'] = $this->model_user->Dropdown_date ( 'birthday_y', set_value( 'birthday_y' ), 'year', FALSE );

                        $data['values']['country_code']     = set_value( 'country_code' );

                        $this->load->view( $data['theme_folder_vault'] . 'master-user-set_info.php', $data );

                    break;


                    case TRUE:

                        /* this can be replaced with foreach code for POST and propper element names */
                        $data_post['name']              = $this->input->post ('name');
                        $data_post['city_id']           = $this->input->post ('city_id');
                        $data_post['work']              = $this->input->post ('work');
                        $data_post['country_code']      = $this->input->post ('country_code');


                        //FIX for WRONG CITY/COUNTRY BUG
                        $city_id         = $this->input->post ('city_id');
                        $country_code     = $this->input->post ('country_code');
                        if ( $this->model_user->Custom_City_Check( $country_code, $city_id ) == FALSE )
                        {
                            $data_post['city_id'] = -1;
                        }                

                        
                        $data_post['birthday']     = set_value( 'birthday_y' ) .'-'. set_value( 'birthday_m' ) .'-'. set_value( 'birthday_d' ) ;
                        

                        // echo '<pre>';
                        // print_r( $data_post );
                        // echo '</pre>';
                        // die();                  

                        $user_id = $this->model_user->Session_UserID();

                        $info_result = $this->model_user->User_SetUserInfo( $user_id, $data_post );

                        redirect ( 'user/settings/success' );

                    break;


                    default:
                        die ( 'error - ftw? ');
                    break;
                }


            break;

look at the dummy line

#6
[eluser]The Wizard[/eluser]
btw, ive made a workarround where i change the value of the post array to a value, where it does not
fit into the validation, so the validation automatically fails.

#7
[eluser]RJ[/eluser]
I've narrowed it down to a redirect problem
Code:
$redirect = ''.$this->lang->lang.'/shop/device/'.$this->dealer->dealer.'/plan';
            log_message('debug',  'REDIRECT :'.$redirect.'');
            redirect($redirect);

Looks all goofy because I've been trying to break it down to the error. it appears the /plan part of theURI is not being passed! I see it in the log

Quote:REDIRECT :en/shop/device/999/plan

Any thoughts?

#8
[eluser]TheFuzzy0ne[/eluser]
Deja vu - http://ellislab.com/forums/viewthread/113414/

I don't get it. Is it solved? If so, please could you mention how you did it?

#9
[eluser]RJ[/eluser]
@TheFuzzyOne Hey man knew you were on the board somewhere, the two issues ran together, couldn't figure it out for a while but finally it came to me from the heavens above!! Smile

I'll post the solution in the redirect thread as that is more relevant.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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