'doEdit', 'update' => 'doUpdate', 'cancel' => 'doEdit', ); var $functionalFields = array('id', 'name', 'label', 'value', 'type' , 'options', 'added', 'changed', ); function _bindFormFields($form) { $form = parent::_bindFormFields($form); $data = $this->DBObj->_data; $fields = $this->DBObj->getList4Grid(); if (is_array($fields)){ foreach ($fields['list'] as $field) { $name = $field['name']; $value = $data[$name]; $label = $field['label']; $type = $field['type']; $options = $field['options']; $form->removeElement($name); switch ($type) { case 'date': $date = Form::createElement('calendar', $name, $label); $date->setValue( $value ); $form->addElement($date); break; case 'select': $sel = Form::createElement('select', $name, $label, $this->_getSelOpts($options)); $sel->setSelected($value); $form->addElement($sel); break; case 'bool': $chk = Form::createElement('checkbox', $name, $label, '', array('value' => 1)); $chk->setChecked((bool)$value); $form->addElement($chk); break; case 'file': $el = Form::createElement('file_db', $name, $label, $value, ''); $form->addElement($el); break; case 'html_editor_basic': $form->addElement('html_editor_basic', $name, $label)->setValue($value); break; case 'emails': $gEmails = array(); $gEmails[0]= Form::createElement('textarea', $name, NULL, array('rows'=>'3', 'style' => 'width:98%;')); $gEmails[0]->setValue($value); $gEmails[]=Form::createElement('static', 'emails_static', NULL, '  Note: You may enter one or more email addresses above separated by commas'); $form->addGroup($gEmails, 'gEmails', $label, '
', false); $form->addFormRule(array($this, 'validateEmails')); break; case 'header': $el = Form::createElement('header', $name, $label); $form->addElement($el); default: $form->addElement('text', $name, $label, array('value' => $value, 'size' => 40)); if ('header' != $type){ $form->addRule($name, 'Field \'' . $label . '\' is required', 'required'); $form->addRule($name, 'Field \'' . $label . '\' is required', 'required', null, 'client'); } if ($type == 'email') { $form->addRule($name, 'Wrong email address in \'' . $label . '\' field', 'email'); $form->addRule($name, 'Wrong email address in \'' . $label . '\' field', 'email', null, 'client'); } elseif ($type == 'float') { $form->addRule($name, 'Wrong data in \'' . $label . '\' field', 'numeric'); $form->addRule($name, 'Wrong data in \'' . $label . '\' field', 'numeric', null, 'client'); } elseif ($type == 'int') { //vdie($form->getRegisteredRules()); $form->addRule($name, 'Wrong data in \'' . $label . '\' field', 'regex', "/^[\-0-9]+$/"); $form->addRule($name, 'Wrong data in \'' . $label . '\' field', 'regex', "/^[\-0-9]+$/", 'client'); } break; } } } return $form; } function validateEmails($fields) { $err = array(); $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/'; $fields['admin_email'] = preg_replace('/[\r\n]+/',' ', $fields['admin_email']); $arrEmails = split('[, ;]', $fields['admin_email']); foreach ($arrEmails as $k=>$v) { if (!strlen(trim($v, ',; '))) unset($arrEmails[$k]); } $arrEmails = array_unique($arrEmails); $errEmails = array(); foreach ($arrEmails as $k=>$email) { if (!preg_match($regex, $email)) { $errEmails[] = $email; } } if (count($errEmails)) $err['gEmails'] = 'Wrong email address ('.implode(', ',$errEmails).')'; return (count($err))?$err:true; } function _getSelOpts($optionsStr) { $optSep = '|'; $kvSep = '=>'; $optionsAsoc = array(); $optionList = explode($optSep, $optionsStr); foreach ($optionList as $option) { list($key , $val) = explode($kvSep, $option); $optionsAsoc[$key] = $val; } return $optionsAsoc; } }