Welcome Guest, Not a member yet? Register   Sign In
Calculate Age In Controller Using Call Back Function
#1

[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]');
            $this->form_validation->set_rules('mem_type','Membership Type','required');
            $this->form_validation->set_rules('referral','Reference ID','required');
            $this->form_validation->set_rules('lastname','Last Name','required');
            $this->form_validation->set_rules('firstname','First Name','required');
            $this->form_validation->set_rules('middlename','Middle Name','required');
            $this->form_validation->set_rules('email','Email Address','required|is_unique[member.email]|valid_email');
            $this->form_validation->set_rules('contact','Mobile Number','required|numeric|is_unique[member.mobile_number]');
            $this->form_validation->set_rules('gender','Gender','required');
            $this->form_validation->set_rules('address','Address','required|xss_clean');
            $this->form_validation->set_rules('year','Year','required');
            $this->form_validation->set_rules('month','Month','required');
            $this->form_validation->set_rules('day','Day','required');        
            $this->form_validation->set_rules('password','Password','required|matches[passcon]|min_length[8]|max_length[16]');
            $this->form_validation->set_rules('passcon','Password Confirm','required');
            $this->form_validation->set_rules('tin','Tin','required');
            
            if($this->form_validation->run() == FALSE){
                $this->load->view('sites/addNewMember.php');
                $this->load->view('templates/footer');
            }
            else{
                $this->payment_model->addMemberInfo();
                $this->load->view('sites/success');
            }

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');
                $month = $this->input->post('month');
                $day = $this->input->post('day');
                
                $birthday = $year.'-'.$month.'-'.$day;
                
                $member = array(
                    'member_id' => null,
                    'account_type' => $this->input->post('mem_type'),
                    'username' => strtolower($this->input->post('username')),
                    'account_type' => $this->input->post('mem_type'),
                    'lastname' => ucwords($this->input->post('lastname')),
                    'firstname' => ucwords($this->input->post('firstname')),
                    'middlename' => ucwords($this->input->post('middlename')),
                    'gender' => $this->input->post('gender'),
                    'address' => ucwords($this->input->post('address')),
                    'birthday' => $birthday,
                    'email' => strtolower($this->input->post('email')),
                    'mobile_number' => $this->input->post('contact'),
                    'password' => md5($this->input->post('password')),
                    'tin' => $this->input->post('tin'),
                    'upline' => 'none',
                    'account_created' => date('Y-m-d h:i:s')
                );
              
                    $insert =  $this->db->insert('member',$member);
                    $memberid = mysql_insert_id();
                    $this->session->set_userdata('member_id',$memberid);
                
                    return $insert;


Messages In This Thread
Calculate Age In Controller Using Call Back Function - by El Forum - 10-11-2012, 09:24 PM
Calculate Age In Controller Using Call Back Function - by El Forum - 10-12-2012, 02:12 AM
Calculate Age In Controller Using Call Back Function - by El Forum - 10-12-2012, 02:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB