Welcome Guest, Not a member yet? Register   Sign In
Display validation message seperately
#1

[eluser]cinewbie81[/eluser]
Code:
______________________
|        |           |
|        |           |    
|        |           |    
|        |           |    
|    A   |    B      |    
|        |           |
|        |           |
|        |           |    
|        |           |    
|________|___________|

I have a form as shown above.

'A' is the registration module and has the fields such as Name, IC Number, Phone Number, Email etc

Whereas 'B' is the login module with 'username' and 'password' fields.

Both of them are under the same form.

'A' has its own validation, and i want the validation error to be displayed above 'A'.
Whereas 'B' has its own validation and the validation error need to be displayed above 'B'.

My current code will display both validation error on top of 'A' and 'B' together. I want it to be seperately, for eg: Login Validation error will only display the validation message on top of 'B' but not in 'A' ...

Anyone?
#2

[eluser]xwero[/eluser]
add in each section a error variable (error_a,error_b), you split up the validation for the two parts if you didn't do that already an in you controller you assign the error message to the appropriate error variable.
#3

[eluser]cinewbie81[/eluser]
Hi xwero, thanks for your reply .. but i dont quite understand how u mean ..
how can i add a error variable ??? See the following codes :

Code:
$rules['name'] = "required|max_length[100]";
    $rules['password'] = "required|max_length[100]";
    $this->validation->set_rules($rules);

    $fields['name'] = 'Login Name';
    $fields['password'] = 'Login Password';
    $this->validation->set_fields($fields);

    if ($this->validation->run() == FALSE)
    {
        $this->load->view('login_view');
    }  else {
        // Input success
    }

login_view form
Code:
<div id="validation">
    &lt;?php echo $this->validation->error_string; ?&gt;
</div>

In the above code, how can i add another error variable ?? thanks
#4

[eluser]xwero[/eluser]
view
Code:
&lt;form action="" method="post"&gt;
<div id="a">
  <div id="validationa">&lt;?php echo $errora; ?&gt;</div>
  &lt;!-- form --&gt;
  &lt;input type="submit" name="register" value="Register"&gt;
</div>
<div id="b">
<div id="validationb">&lt;?php echo $errorb; ?&gt;</div>
  &lt;!-- form --&gt;
  &lt;input type="submit" name="login" value="Login"&gt;
</div>
&lt;/form&gt;
controller
Code:
$data['errora'] = '';
$data['errorb'] = '';
$rules['name'] = "required|max_length[100]";
    $rules['password'] = "required|max_length[100]";
    $this->validation->set_rules($rules);

    $fields['name'] = 'Login Name';
    $fields['password'] = 'Login Password';
    $this->validation->set_fields($fields);

    if ($this->validation->run() == FALSE)
    {
        if($this->input->post('register'))
        {
          $data['errora'] = $this->validation->error_string;
        }
        if($this->input->post('login'))
        {
          $data['errorb'] = $this->validation->error_string;
        }
        $this->load->view('login_view',$data);
    }  else {
        // Input success
    }
#5

[eluser]cinewbie81[/eluser]
It works ..
Thanks champs !!
#6

[eluser]dejitaru[/eluser]
I tried and it works but when sucess I have my insert there, but is having an error:
Error Number: 1054
Unknown column 'register' in 'field list'

Inside success I have this code:
$this->db->insert('comentarios',$this->input->xss_clean($_POST));
#7

[eluser]xwero[/eluser]
Your $_POST array contains all inputs send with the request. It's not a good idea to put the $_POST global directly into the query. Do this instead
Code:
$fields = array('field1'=>$this->input->post('field1',true),'field2'=>$this->input->post('field2',true));
$this->db->set($fields);
$this->db->insert(’comentarios’);
It is more typing but you could use the xss clean setting in the config file so you don't have to add the second argument to the post method.
#8

[eluser]dejitaru[/eluser]
It worked, thanks. maybe a function like deleteFields($pData,$fieldsToDelete) could help if my form is large.
^_^




Theme © iAndrew 2016 - Forum software by © MyBB