Calculate Age In Controller Using Call Back Function |
[eluser]rochellecanale[/eluser]
hello guys I need a little help. My problem is how can I create a callback function in validating age. Here's my controller: Code: $this->form_validation->set_rules('username','Username','required|trim|min_length[8]|max_length[15]|is_unique[member.username]'); How can i validate the age inputted in the field. For example I want to validate if the user is 18 years old and above. If 18 the user may proceed if not it will validate and display message "User must be 18 years old and above to gain a membership!! All my $this->input->post() is in my model should i call this also in my controller? or should i validate it in the model function? Please give me an idea how to do this. Here;s my code in the model below: Code: $year = $this->input->post('year');
[eluser]boltsabre[/eluser]
It's in the documentation, it's called a validation callback function: http://ellislab.com/codeigniter/user-gui...#callbacks Also, controller: You're loading your a view like Code: $this->load->view('sites/addNewMember.php'); Also, after success you are just loading a new view like this: Code: else{ Use "redirect()" (to a success controller) when the form has been successfully submitted. Also, in your model: Code: $month = $this->input->post('month'); - $day = $this->input->post('day'); is just bad coding, when you don't have to assign it to a new variable, DONT! You could have just as easily coded it like this: Code: ... - reduce the amount of code you type, increasing development time. - also reduce the amount of potential bugs you create in the development process!!! - reduce your server load because: - each time you create a new variable it has to be stored in your server memory, increasing the chance of creating server load related problems. - and it reduces the amount of code the server has to load and run at compile time! And lastly, you should research some method of checking if your insert/update actually worked! What happens if your mysql server was down when this code ran... it just returns $insert, which could be false if the server was down (thus nothing was actually inserted), and you redirect your user to the success page and they will think they have created an account when in reality it wasn't created! good luck!
|
Welcome Guest, Not a member yet? Register Sign In |