• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's Wrong Here?

#1
[eluser]charlie spider[/eluser]
Ever have a problem right in front of your eyes but you just don't see it ?

The problem:

validation errors the instant my form is loaded for the VERY FIRST TIME !!!


Can't figure out what i'm overlooking.

Here's the controller:

Code:
function add_boot()
{
    if ($this->session->userdata('logged_in'))
    {
        $this->load->helper('assets');
        $this->load->helper('form');
        $this->load->helper('html');
        $this->load->library('validation');
        $this->load->model('CMS_model');
        $this->load->model('Boot_model');
        
        require('includes/navigation.php');
        
        $data['status'] = $this->load->view('modules/status', $data, TRUE);
        $data['menu'] = $this->load->view('modules/menu', $data, TRUE);
        
        $data['page'] = 'add_boots';
        $data['pageInfo'] = array('pageName' => 'Add New Boot');
        $data['error_msg'] = "";
                    
        $data['type'] = $this->Boot_model->get_boot_types(0);
        $data['java'] = '';                
        $data['keywords'] = '';
        $data['metadesc'] = '';
        
        $rules['add_boot_type'] = "required";
        $rules['add_boot_nmbr'] = "trim|required|min_length[2]|max_length[12]";
        $rules['add_boot_name'] = "trim|required|min_length[4]|max_length[24]";
            
        $this->validation->set_rules($rules);                
            
        $this->validation->set_error_delimiters('<div class="error">', '</div>');
        
        $fields['add_boot_type']    = 'Boot Type';
        $fields['add_boot_nmbr']    = 'Boot Number';
        $fields['add_boot_name']    = 'Boot Name';
        
        $this->validation->set_fields($fields);
                    
        if ($this->validation->run() == TRUE)    
        {
            // get new bootID from database then go to cms/boot/$bootID
        }
        else
        {
            $data['content'] = $this->load->view('modules/cms_add_boot', $data, TRUE);            
            $this->load->view('modules/cms_view', $data);
        }
    
    }
        
    else {  redirect('cms', 'refresh'); }
}





and here's the 'modules/cms_add_boot' view:

note: 'modules/cms_view' is a generic container view that all of my content gets loaded into. It's basically all of the header, navigation and footer stuff for the page with a &lt;?=$content;?&gt; tag in the middle of it.


Code:
&lt;form acti&gt;
<h4>Select Boot Type</h4>
&lt;?=$this->validation->add_boot_type_error; ?&gt;
<h5>Boot Type</h5><br />

<select name="add_boot_type" class="dropdown">
<option value=""></option>
&lt;?php
foreach ( $type as $key => $value )
{ ?&gt;
<option value="&lt;?=$key;?&gt;" &lt;?=$this->validation->set_select('add_boot_type', $key);?&gt; >&lt;?=utf8_decode($value);?&gt;&nbsp;&nbsp;&nbsp;</option>
&lt;?php } ?&gt;
</select>
<br /><br />


<h3>Choose Unique Boot Number and Name</h3>
&lt;?=$this->validation->add_boot_nmbr_error;?&gt;

<h5>Boot Number</h5><br />
&lt;input name="add_boot_nmbr" class="login" type="text" size="12" maxlength="12" value="&lt;?=$this-&gt;validation->add_boot_nmbr;?&gt;" />

&lt;?=$this->validation->add_boot_name_error; ?&gt;
<h5>Boot Name</h5><br />
&lt;input name="add_boot_name" class="login" type="text" size="12" maxlength="12" value="&lt;?=$this-&gt;validation->add_boot_name;?&gt;" />
<br />
&lt;input name="add_boot" type="submit" value="Create New Boot" class="login"/&gt;
&lt;/form&gt;


Thanks for any and all help.

#2
[eluser]ontguy[/eluser]
Is error it gives is as if the form has already been submitted?

What does the output of this look like the first time?
Code:
print_r($_POST);

#3
[eluser]Armchair Samurai[/eluser]
Sounds like you've got $_POST data being submitted to the page: does the user navigate to add_boot through a form submission?

#4
[eluser]charlie spider[/eluser]
Armchair Samurai - you win the prize.

i used a "Add New Boot" button to get to the page. Didn't know that would trigger the validation. I will change it to a regular link.

ontguy - you get the consolation prize for helping out.

Thanks guys! very appreciated


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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