Welcome Guest, Not a member yet? Register   Sign In
form validation doesn't work !!!!
#1

[eluser]amira_fcis[/eluser]
hi all,
this is the first time i tried to use form validation library to chek my form fields,but i found a problem which is:
i have a form that make update to user information through db,it works well.but the problem is when i skip any field in form that i made a validation to ...no messages appear to say User name field is empty.

i'll be greatfull for any help
Code:
function updateUser()
          {
            $this->load->database();
            $this->load->library('form_validation');
            $this->load->helper(array('form', 'url'));
            $this->load->model('User');
        
           $userServices=new UserServices();
           $userDAO = new UserDAO();
        
        $this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');
        $this->form_validation->set_rules('firstname', 'First Name', 'required|min_length[5]|max_length[12]');
        $this->form_validation->set_rules('lastname', 'Last Name', 'required|min_length[5]|max_length[12]');
        $this->form_validation->set_rules('title', 'Title', 'min_length[2]|max_length[5]');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'required|matches[confirmpassword]');
        $this->form_validation->set_rules('confirmpassword', 'Password Confirmation', 'required');
        
        $this->form_validation->set_rules('city', 'City', 'required');
        $this->form_validation->set_rules('phoneno', 'Phone No', 'min_length[5]|max_length[12]');
        $this->form_validation->set_rules('cellphoneno', 'Cell Phone No', 'required|min_length[5]|max_length[12]');

            
        if (!$this->form_validation->run())
        {
        $data['users']=array();
        $this->User->setUserID($this->input->post('userid'));
        $data['users']=$userDAO->retrieveUser( $this->User,$this);
            $this->load->view('Edit_form',$data);    

            
        }
        else
        {
                $this->User->setUserName($this->input->post('username'));
                $this->User->setUserFName($this->input->post('firstname'));
                $this->User->setUserLName($this->input->post('lastname'));
                $this->User->setUserTitle($this->input->post('title'));
                $this->User->setUserEmail($this->input->post('email'));
                $this->User->setUserPassword($this->input->post('password'));
                $this->User->setUserAddress($this->input->post('address'));
                $this->User->setUserCity($this->input->post('city'));
                $this->User->setUserPhoneNo($this->input->post('phoneno'));
                $this->User->setUserCellPhoneNo($this->input->post('cellphoneno'));
                
                $this->User->setUserID($this->input->post('userid'));
                
                 $resUpdate=$userServices->updateUserAccount($this->User,$this);
                   if( $resUpdate){
                       $data['All']=$userServices->listAllUsers($this);
                       $this->load->view('users_view',$data);
                  }
        }
          
        
          }

here is the form
Code:
<html>
<head>
<title>Edit Form</title>
</head>
<body>


<?php echo validation_errors(); ?>

<?php echo form_open('EditUser/updateUser'); ?>

<?
if($users)
{
foreach( $users as $user)
         {

?>
<input type="hidden" name="userid" value="<?echo $user->getUserID() ;?>" size="50" />
    <?php echo form_error('username'); ?>
User Name    &lt;input type="text" name="username" value="&lt;?echo $user-&gt;getUserName() ;?&gt;"/><br><br>
    &lt;?php echo form_error('firstname'); ?&gt;
First Name   &lt;input type="text" name="firstname" value="&lt;?echo $user-&gt;getUserFName() ;?&gt;"/><br><br>
    &lt;?php echo form_error('lastname'); ?&gt;
Last Name    &lt;input type="text" name="lastname" value="&lt;?echo $user-&gt;getUserLName() ;?&gt;" /><br><br>
    &lt;?php echo form_error('title'); ?&gt;
Title        &lt;input type="text" name="title" value="&lt;?echo $user-&gt;getUserTitle() ;?&gt;" /><br><br>
    &lt;?php echo form_error('email'); ?&gt;
Email        &lt;input type="text" name="email" value="&lt;?echo $user-&gt;getUserEmail() ;?&gt;" /><br><br>
    &lt;?php echo form_error('password'); ?&gt;
Password     &lt;input type="password" name="password" value="&lt;?echo $user-&gt;getUserPassword() ;?&gt;" /><br><br>
    &lt;?php echo form_error('confirmpassword'); ?&gt;
Confirm Password   &lt;input type="password" name="confirmpassword" value="" /&gt;&lt;br><br>

Address            &lt;input type="text" name="address" value="&lt;?echo $user-&gt;getUserAddress() ;?&gt;"  /><br><br>
    &lt;?php echo form_error('city'); ?&gt;
City               &lt;input type="text" name="city" value="&lt;?echo $user-&gt;getUserCity() ;?&gt;" /><br><br>
    &lt;?php echo form_error('phoneno'); ?&gt;
Phone No           &lt;input type="text" name="phoneno" value="&lt;?echo $user-&gt;getUserPhoneNo() ;?&gt;"/><br><br>
    &lt;?php echo form_error('cellphoneno'); ?&gt;
Cell-Phone No      &lt;input type="text" name="cellphoneno" value="&lt;?echo $user-&gt;getUserCellPhoneNo() ;?&gt;"/><br><br>
&lt;?
}
}
?&gt;

&lt;input type="submit" value="Update" /&gt;

&lt;/form&gt;
  &lt;/body&gt;
    &lt;/html&gt;
#2

[eluser]amira_fcis[/eluser]
Hmmm, no-one got any ideas then?
#3

[eluser]CroNiX[/eluser]
Im not positive but it could be because you aren't using the validation methods for setting the data in your view? Like set_value();
#4

[eluser]amira_fcis[/eluser]
thanks for ur concern,
but i tried this before and it works well.but when i added the lines
Code:
$this->User->setUserID($this->input->post('userid'));
        $data['users']=$userDAO->retrieveUser( $this->User,$this);

before
Code:
$this->load->view('Edit_form',$data);
the problem appears Sad i donnot know why!!!!!!!
#5

[eluser]CroNiX[/eluser]
Well it appears that you are setting the values to the database values regardless of what the user enters in the form?

Maybe check for the submitted form (by checking for $this->input->post('submit')), if its not present (form not submitted) get values from db, if is set, use form values. To do that though you need to NAME your submit (your only setting a value).

Code:
if ($this->input->post('submit') && ! $this->form_validation->run())
#6

[eluser]amira_fcis[/eluser]
Code:
if ($this->input->post('submit') && ! $this->form_validation->run())
        {
        
        
        $this->User->setUserID($this->input->post('userid'));
        $data['users']=$userDAO->retrieveUser( $this->User,$this);
        
           $this->load->view('Edit_form',$data);    
            
        }

it still doesn't appear the error messeges
#7

[eluser]amira_fcis[/eluser]
i tend to be crazy from checking all possible solution as far as o know but no changes happened..:zip:

any new ideas...!!!!
#8

[eluser]amira_fcis[/eluser]
ANY HELPPPPPPPPPPPPPPPPPPPPPPPPPPP




Theme © iAndrew 2016 - Forum software by © MyBB