Welcome Guest, Not a member yet? Register   Sign In
form validation
#1

[eluser]pam81[/eluser]
Hi, i'm using form validation in a login form it works ok but i have problems with the url
first time when form is no valid i see this
http://127.0.0.1/cartanatal/index.php/login/validate
the second time
http://127.0.0.1/cartanatal/index.php/lo...n/validate
the tirhd time
http://127.0.0.1/cartanatal/index.php/lo...n/validate
all the time it add another "login" to the url

here is the code of the controller wich is call from the form.
I would like too know if there is another way to use form validation
Thanks in advance!


Code:
class Login extends Controller {
    
  function __construct() {
    parent::Controller();
      $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
           $this->load->library('session');
           $this->session->set_userdata('login', 'noaccepted');
    }
  
  function index()
  {
            
            $this->load->view('adm/adm_view_header');
            $this->load->view('adm/loginform_view');
            $this->load->view('adm/adm_view_footer');
  }
  
  function validate()
    {
        $this->form_validation->set_rules('username', 'Usuario', 'trim|required|min_length[3]|max_length[20]|xss_clean');
        $this->form_validation->set_rules('password', 'Clave', 'trim|required');
                
        if ($this->form_validation->run() == FALSE )
        {
              $this->load->view('adm/adm_view_header');
                  $this->load->view('adm/loginform_view');
                  $this->load->view('adm/adm_view_footer');                
        }
        else
        {
           $this->load->model('User_model');
      $valido = $this->User_model->validateUser($this->input->post('username'),$this->input->post('password'));
      if ($valido)
      {
         $this->session->set_userdata('login_cartanatal', 'accepted');
          redirect('adm/index');
      }
      else
      {  
                  $data["error"]="Not Login";
                  $this->load->view('adm/adm_view_header');
                  $this->load->view('adm/loginform_view',$data);
                  $this->load->view('adm/adm_view_footer');
          
      }  
        }
        
    }
}
#2

[eluser]n0xie[/eluser]
It has most likely to do with your view. Show us the adm/loginform_view.
#3

[eluser]pam81[/eluser]
My view is basically a form i add the validation_errors to show the errors

Code:
<?php echo validation_errors(); ?>
            <form method="post" name="loginform" action="login/validate">
            <td height="60" align="center" valign="middle" bgcolor="#D6D6D6">&lt;input name="username" type="text" class="txtbox120" id="textfield" value="" /&gt;&lt;/td>
            <td height="60" align="center" valign="middle" bgcolor="#D6D6D6">&lt;input name="password" type="password" class="txtbox120" id="textfield2" value="" /&gt;&lt;/td>
            <td height="60" align="center" valign="middle" bgcolor="#D6D6D6"> <img src="&lt;?php echo base_url();?&gt;images/but_asp_31.gif" alt="Entrar" name="taro" width="85" height="21" vspace="3" border="0" id="taro"> </td>
            &lt;/form&gt;
#4

[eluser]n0xie[/eluser]
[quote author="pam81" date="1273705801"]
Code:
&lt;form method="post" name="loginform" action="login/validate"&gt;
[/quote]
This is where it goes wrong. Either use the URL helper and use site_url, use the form helper and use form_open(), or add a slash at the beginning. Since you're not stating that it should look at the root of your webserver folder, it appends login to your uri.
#5

[eluser]pam81[/eluser]
Thanks so much!!! It was the error. Now it works fine. I put site_url before the address.




Theme © iAndrew 2016 - Forum software by © MyBB