Hi!

How to handle null values in select elements?

For example I have table:
User {
  region_id: foreign key, can be null
  ..ect
}

I have select with prompt:
<select name="region_id">
 <option value="-1">Please select region</option>
 <option value="1">Region1</option>
 ..etc
</select>

in UsersController::createAction():
$form = new User_Form(); // Zend_Form instance
// handle $_POST data etc.
$data = $form->getValues(true);
// and very ugly:
if ($data['region_id'] == -1) $data['region_id'] = null; // !!

$user = new User(); // this is phpDoctrine record
$user->merge($data);
$user->save();

How to get rid of this redundant code?
Problem is very painful when I have large tables with FK or when I create
records in several places in the code.
-- 
View this message in context: 
http://www.nabble.com/Zend_Form_Element_Select-and-null-values-tp16700805p16700805.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to