Welcome Guest, Not a member yet? Register   Sign In
URI keeps adding values as form validation fails
#1

[eluser]RJ[/eluser]
Hello,

Sorry so many posts today, having some issues and difficulty resolving permanently. My URI looks like:
Quote:s/en/shop/device

the device method looks like
Quote:function device($dealer = '999', $page = 'personal_information', $debug = FALSE)

upon form validation failure the URI changes to
Quote:s/en/shop/device/999

if it fails again the uri looks like
Quote:s/en/shop/device/999/999

Is me setting a default value in the var the cause of this?
#2

[eluser]TheFuzzy0ne[/eluser]
What's the code that does the redirecting?
#3

[eluser]RJ[/eluser]
I'm going to change the way I switch between pages and see if that'll solve the problem, i'll let you know, ty!
#4

[eluser]RJ[/eluser]
Hmmm.. still happening. and of course once the extra 999 is added now the second var for my device method is assign 999 rather than default killing the page. here is my method:
Code:
function device($dealer = FALSE, $page = 'personal_information', $debug = FALSE)
    {
        if (!$dealer)
        {
            $dealer = '999';
        }
        // begin benchmarking
        $this->benchmark->mark('code_start');
        if($debug == true) {$this->error_debug = true;}

        $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
        $this->load->model('sql_model','sql');

        // Set dealer params
        $this->dealer->set_dealer($dealer);        // passes db info to dealer model for processing
        $this->load->model('Trimtrac_model', 'trimtrac');   // load trimtrac
        $this->load->helper(array('form'));                    // load form helper
        

        //echo $this->lang->lang;
        switch($page)
        {
            case "personal_information":

                // Load stuff
                //$this->common->on_screen($this->sql->build_display('US','GPRS','999'));
                $this->load->library('form_validation');            // load libraries
                $this->form_validation->set_error_delimiters('<pre class="alert">', '</pre>');
                $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', 'Welcome White Label');
                    $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
                    if($this->error_debug)
                    {
                       log_message('debug',  'VALIDATION OK, ADD TO SESSION');
                    }

                    // build session
                    $session = array(
                                'country' => $this->input->post('country'),
                                'terms' => $this->input->post('terms')
                            );
                    // write to session
                    $this->session->set_userdata($session);
                    log_message('debug',  'SESSION VALUES ADDED, NOW SEND TO PAGE TWO');

                    // redirect to page two
                    $redirect = ''.uri_string().'/plan_information';
                    log_message('debug',  'REDIRECT :'.$redirect.'');
                    redirect($redirect, 'refresh');

                }
                //$this->page_one();
                break;
            
            case "plan_information":
                if($this->error_debug)
                {
                    log_message('debug',  'WE MADE IT! WELCOME TO PAGE TWO');
                }
}
#5

[eluser]tomcode[/eluser]
I haven't read Your code, but usually this kind of behaviour You get when using uri_string()
#6

[eluser]RJ[/eluser]
@tomcode exactly!

Appears to be the form open tag. For page one I have:
Code:
&lt;?= form_open(uri_string().'/'.$num) ?&gt;

So after we're submitted the uri_string() now has the dealer code already in it and I'm adding again. Doh!

Thanks
#7

[eluser]TheFuzzy0ne[/eluser]
A simple check to see if the segment doesn't exist first before setting the number should work nicely.




Theme © iAndrew 2016 - Forum software by © MyBB