Welcome Guest, Not a member yet? Register   Sign In
[HELP] - Error handeling for a form
#1

[eluser]Bainzy[/eluser]
Hi everybody,

Today i started to make a registration form for my site, everything is going fine so far but now i have run into a little problem and i dont know how to cure it.

Basically i have the following fields

Username
Nickname
Password
Confirm Password
Email
Confirm Email

Now at the minute i am using codeigniteres built in form helper so to show the simple errors like boxes not being filled in and returning the user to the form showing these errors. Thats all great.

The part i am stuck on it once all the boxes are filled in and its passed to my controller for processing, i want to compair the two password entries to make sure they match and then the same with the two email fields, if either of these do not match i would like to return the user to the form and show the error for the user to correct, now i dont know if there is something in codeigniter which i can use to do this.

I thought i had it working with the following code :

Code:
// The user has entered all the data, now check the data
               if($this->input->post('password') == $this->input->post('cpassword'))
               {
                   // If the two passwords match then do nothing
            }
            else
            {
                $data = array();
                $data['error'] = 'Passwords do not match please try again!';
                $this->load->view('register', $data);
            }

Now here is my register form to show these errors :

Code:
<?php
if($error)
{
    echo '<div id="errorBox">
    <h3>Woops, there is a problem</h3>
    <p>'.$error.'</p>
    <p>'.form_error('username').'</p>
    <p>'.form_error('nickname').'</p>
    <p>'.form_error('password').'</p>
    <p>'.form_error('cpassword').'</p>
    <p>'.form_error('email').'</p>
    <p>'.form_error('cemail').'</p>
    </div>';
}
?&gt;

This shows a box at the top of the page with all the errors for that page so its not cluttering my form, this worked perfect untill i modified my code like this :

Code:
// The user has entered all the data, now check the data
               if($this->input->post('password') == $this->input->post('cpassword'))
               {
                   // If the two passwords match then do nothing
            }
            else
            {
                $data = array();
                $data['error'] = 'Passwords do not match please try again!';
                $this->load->view('register', $data);
            }
            
            if($this->input->post('email') == $this->input->post('cemail'))
            {
                // If the emails match then do nothing
            }
            else
            {
                $data = array();
                $data['error'] = 'Emails do not match please try again!';
                $this->load->view('register', $data);
            }

Now whats happening its still working fine, however the page is loaded twice, one under each other with the seperate errors shown, this is obviously not what i want.

Now i know my code aint perfect, far from it, however how is the best way to go about handeling this ?

Regards
Chris
#2

[eluser]Bainzy[/eluser]
Does not matter close this topic, just saw the matches function.




Theme © iAndrew 2016 - Forum software by © MyBB