Welcome Guest, Not a member yet? Register   Sign In
Problem with Validation when using an image submit button
#4

[eluser]Oussama M Billah[/eluser]
here is the controller :

Code:
function index(){
        $this->load->library(array('form_validation', 'session'));
            
            // LOAD HELPERS
            $this->load->helper(array('form', 'url'));
            
            // SET VALIDATION RULES
            $this->form_validation->set_message('required', 'The %s field is required. <br/>');
            $this->form_validation->set_message('valid_email', 'The %s field must contain a valid email address. <br/>');
            $this->form_validation->set_message('min_length', 'The %s field must be at least 6 characters in length. <br/>');
            $this->form_validation->set_message('matches', 'The %s field does not match the password field. <br/>');
            
            
            $this->form_validation->set_rules('userName', 'username', 'required');
            $this->form_validation->set_rules('password', 'password', 'required|min_length[6]|');
            $this->form_validation->set_rules('confirmPassword', 'confirm Password', 'required|matches[password]');
            $this->form_validation->set_rules('firstName', 'first name', 'required');
            $this->form_validation->set_rules('lastName', 'last name', 'required');
            $this->form_validation->set_rules('email', 'email address', 'required|valid_email');
    
            $this->form_validation->set_error_delimiters('<em>','</em>');
            
            // has the form been submitted and with valid form info (not empty values)
            if($this->input->post('register_x'))
            {
                if($this->form_validation->run())
                {    
                    $userName = $this->input->post('userName');
                    $user = $this->CustomerModel->getCustomer($userName);
                    if($user->getUserName()){
                        $this->session->set_flashdata('message', 'user already exists! Try again');
                        redirect('register');
                    }

                    $password = $this->input->post('password');
                    $confirmPass = $this->input->post('confirmPassword');
                    $fname = $this->input->post('firstName');
                    $lname = $this->input->post('lastName');
                    $email = $this->input->post('email');
    
                    $customer = new Customer();
                    $customer->setUserName($userName);
                    $customer->setPassword($password);
                    $customer->setFirstName($fname);
                    $customer->setLastName($lname);
                    $customer->setEmailAddress($email);
                        $this->CustomerModel->register($customer);
                        $this->session->set_userdata('user', $userName);
                        return redirect('products');        
                }
            }
            $this->load->view('register.php');                    
            
    }


here is the form code in my view:

Code:
<div class="register_error">
    &lt;?php
      $this->load->library('form_validation');
      if($this->session->flashdata('message')){
       echo $this->session->flashdata('message');
       }
        echo form_error('userName');
           echo form_error('password');
        echo form_error('confirmPassword');
        echo form_error('firstName');
        echo form_error('lastName');
        echo form_error('email');
       ?&gt;
    </div>
    &lt;form name="register" action="register" method="post"&gt;
        User Name:<br />
            &lt;input align="right" size="30" name="userName"/&gt;
          Password:<br />
          &lt;input type="password" size="30" name="password" /&gt;
          Confirm Password:<br />
          &lt;input type="password" size="30" name="confirmPassword" /&gt;
First Name:<br />
          &lt;input size="30" name="firstName" /&gt;
          Last Name:<span style="color:#FF0000">* </span><br />
          &lt;input size="30" name="lastName" /&gt;
          Email Address:<span style="color:#FF0000">* </span><br/>
          &lt;input size="35" name="email"/&gt;
          <br />
           &lt;input type="image" name= "register" src="images/register.jpg" alt="register" width="148" height="34" /&gt;&lt;/div>
&lt;/form&gt;
        </div>


Messages In This Thread
Problem with Validation when using an image submit button - by El Forum - 09-07-2009, 05:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB