CodeIgniter Forums

Full Version: Form not getting validated
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]xtremer360[/eluser]
Trying to find out why my form isn't validating correctly.

Code:
$this->form_validation->set_rules('nicknames', 'Nicknames',
        'required');
$this->form_validation->set_rules('hometown', 'Hometown',
        'required');
$this->form_validation->set_rules('height', 'Height',
        'required');
$this->form_validation->set_rules('Weight', 'Weight',
        'required');
$this->form_validation->set_rules('manager', 'Manager',
        'required|integer');  
$this->form_validation->set_rules('setup', 'Setup',
        'required');
$this->form_validation->set_rules('finisher', 'Finisher',
        'required');
$this->form_validation->set_rules('biography', 'Biography',
        'required');

Here is what is getting submitted:

Code:
biography   Kid coming out of college getting the chance of a lifetime.
finisher    Idolizer
height  5'4"
hometown    Las Vegas, Nevada
manager 0
nicknames   "The Quintessential Cruiserweight of KOW!"; "K-Dub"
setup   That's Wondeful
submit  Submit
weight  140 lbs.

El Forum

[eluser]astroanu[/eluser]

can u post your controller's function?

El Forum

[eluser]xtremer360[/eluser]
Code:
function biographySubmit()
    {
        $outputArray = array('error' => 'yes', 'message' => 'unproccessed');
        $outputMsg = '';
        // Sets validation rules for the login form
        $this->form_validation->set_rules('nicknames', 'Nicknames',
            'required');
        $this->form_validation->set_rules('hometown', 'Hometown',
            'required');
        $this->form_validation->set_rules('height', 'Height',
            'required');
        $this->form_validation->set_rules('Weight', 'Weight',
            'required');
        $this->form_validation->set_rules('manager', 'Manager',
            'required|integer');  
        $this->form_validation->set_rules('setup', 'Setup',
            'required');
        $this->form_validation->set_rules('finisher', 'Finisher',
            'required');
        $this->form_validation->set_rules('biography', 'Biography',
            'required');  
    
        // Checks to see if login form was submitted properly(
        if (!$this->form_validation->run())
        {
            $outputArray['message'] =
                'There was a problem submitting the form! Please refresh the window and try again!';
        }
        else
        {
            $bioFields = array($this->input->post('nicknames'), $this->input->post('hometown'), $this->input->post('height'), $this->input->post('weight'), $this->input->post('manager'), $this->input->post('setup'), $this->input->post('finisher'), $this->input->post('biography'));          
            if ($this->bios->updateBiography($this->input->post('nicknames'), $this->input->post('hometown'), $this->input->post('height'), $this->input->post('weight'), $this->input->post('manager'), $this->input->post('setup'), $this->input->post('finisher'), $this->input->post('biography'), $this->session->userdata('defaultRosterListID')))
            {
                $outputArray = array('success' => 'Yes', 'message' =>
                                            'Biography were updated successfully!');
            }
            else
            {
                $outputArray['message'] =
                'The biopgraphy was not able to be updated in the database. Please try again later!';
            }
        }
        echo json_encode($outputArray);
    }

El Forum

[eluser]CroNiX[/eluser]
What exactly isn't working? Each of your fields is required, and they all seem to have a value. One field requires numeric in additional to being required, and it has a 0. So it looks like it passes your rules to me?

El Forum

[eluser]astroanu[/eluser]
interesting. the controller looks fine from here. did u try changing the order of the rules?
'required|integer' to 'integer|required'
for some reason it worked for me in a different situation