Welcome Guest, Not a member yet? Register   Sign In
getPost() not working as expected
#1

Hi,
I have a simple process in my controller, however if the POST of form input 'first_name' is empty, the statement if($this->request->getPost('first_name') ) is evaluated FALSE and (of course) an exception is reported as $data['employee_data']['first_name'] does not exist.

Is this how request->getPost() is supposed to work for empty form input fields?

This is quite annoying especially if the form input firld is optional !


PHP Code:
if($this->request->getGet('emp_no')){
    $data['emp_no']=$this->request->getGet('emp_no');
    $data['employee_data']=$em->getEmployeeById($this->request->getGet('emp_no'));
    
}else{
    if($this->request->getPost('emp_no')){
        $data['emp_no']=$this->request->getPost('emp_no');
    }
}
            
if ($this->request->getPost('first_name')) {                
    $data['first_name'] =$this->request->getPost('first_name'FILTER_SANITIZE_STRING);
}else{            
    $data['first_name'] = $data['employee_data']['first_name'];

Reply


Messages In This Thread
getPost() not working as expected - by 68thorby68 - 10-29-2020, 03:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB