$customers = Arr::assoc_to_keyval(Model_Customer::find('all'), 'id', 'name'); $customers[0] = '- Please select customer -'; asort($customers); $this->template->set_global('customers', $customers);This way i can easily bind the $customers to my dropdown field in the form. Works still great. Now comes the problem: When i submit the form, i want to check if the field is zero, which means "not set" as seen above, and then unset the field so the validation triggers because the field is required. Ive done this in the create action of my controller...
if(Input::post('customer_id') == 0) unset($_POST['customer_id']); $val = Model_Event::validate('create'); if ($val->run()) { ...After the unset function i get a NULL value when i do var_dump(Input::post('customer_id' )) , however the validation dont triggers for this field. Ive searched a while and found out, that the validation uses Input::param() instead of Input::post() to get the field values. So i tried to dump this also right after the unset command. But the strange thing is, that var_dump(Input::param('customer_id' )) gives me a string "0" instead a correct NULL. I guess this is a bug, as param() should show the same values as post() ?? Any idea for a workaround? Thanks
// get the post data $post = \Input::post(); // erase the customer_id if it's value is equal 0 \Input::post('customer_id') === 0 and unset($post['customer_id']); if ($val->run($post)) { // validated ! }
It looks like you're new here. If you want to get involved, click one of these buttons!