Pommo_Fields::makeDB PHP Method

makeDB() static public method

return a field (array)
static public makeDB ( $row )
    static function makeDB($row)
    {
        $in = @array('id' => $row['field_id'], 'active' => $row['field_active'], 'ordering' => $row['field_ordering'], 'name' => $row['field_name'], 'prompt' => $row['field_prompt'], 'normally' => $row['field_normally'], 'required' => $row['field_required'], 'type' => $row['field_type']);
        if (!empty($row['field_array'])) {
            $in['array'] = unserialize($row['field_array']);
        }
        $o = Pommo_Api::getParams(Pommo_Type::field(), $in);
        return $o;
    }

Usage Example

Example #1
0
 $validator->setPost($_POST);
 $validator->addData('field_name', 'Other', false);
 $validator->addData('field_prompt', 'Other', false);
 $validator->addData('field_required', 'matchRegex', false, '!^(on|off)$!');
 $validator->addData('field_active', 'matchRegex', false, '!^(on|off)$!');
 if ($result = $validator->checkData()) {
     // __ FORM IS VALID
     // TODO -> Which below logic is better? the computed diff, or send all fields for update?
     /*
     // make a difference between updated & original field
     $update = array_diff_assoc(Pommo_Fields::makeDB($_POST),$field);
     // restore the ID
     $update['id'] = $field['id'];
     */
     // let MySQL do the difference processing
     $update = Pommo_Fields::makeDB($_POST);
     if (!Pommo_Fields::update($update)) {
         $json->fail('error updating field');
     }
     $json->add('callbackFunction', 'updateField');
     $json->add('callbackParams', $update);
     $json->success(Pommo::_T('Settings updated.'));
 } else {
     // __ FORM NOT VALID
     $fieldErrors = array();
     $errors = $validator->getErrors();
     foreach ($errors as $key => $val) {
         $fieldErrors[] = array('field' => $key, 'message' => $val);
     }
     $json->add('fieldErrors', $fieldErrors);
     $json->fail(Pommo::_T('Please review and correct errors with your submission.'));
All Usage Examples Of Pommo_Fields::makeDB