Пример #1
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // create form
     $this->frm = new FrontendForm('own_question', '#' . FL::getAction('OwnQuestion'));
     $this->frm->addText('name')->setAttributes(array('required' => null));
     $this->frm->addText('email')->setAttributes(array('required' => null, 'type' => 'email'));
     $this->frm->addTextarea('message')->setAttributes(array('required' => null));
 }
Пример #2
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     $this->frm = new FrontendForm('feedback');
     $this->frm->addHidden('question_id', $this->record['id']);
     $this->frm->addTextarea('message');
     $this->frm->addRadiobutton('useful', array(array('label' => FL::lbl('Yes'), 'value' => 'Y'), array('label' => FL::lbl('No'), 'value' => 'N')));
 }
Пример #3
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // create form
     $this->frm = new FrontendForm('commentsForm');
     $this->frm->setAction($this->frm->getAction() . '#' . FL::act('Comment'));
     // init vars
     $author = CommonCookie::exists('comment_author') ? CommonCookie::get('comment_author') : null;
     $email = CommonCookie::exists('comment_email') && \SpoonFilter::isEmail(CommonCookie::get('comment_email')) ? CommonCookie::get('comment_email') : null;
     $website = CommonCookie::exists('comment_website') && \SpoonFilter::isURL(CommonCookie::get('comment_website')) ? CommonCookie::get('comment_website') : 'http://';
     // create elements
     $this->frm->addText('author', $author)->setAttributes(array('required' => null));
     $this->frm->addText('email', $email)->setAttributes(array('required' => null, 'type' => 'email'));
     $this->frm->addText('website', $website, null);
     $this->frm->addTextarea('message')->setAttributes(array('required' => null));
 }
Пример #4
0
 /**
  * Load the form.
  */
 private function loadForm()
 {
     // create form
     $this->frm = new FrontendForm('form' . $this->item['id']);
     // exists and has fields
     if (!empty($this->item) && !empty($this->item['fields'])) {
         //dump($this->item['fields'] );die;
         // loop fields
         foreach ($this->item['fields'] as $field) {
             // init
             $item['name'] = 'field' . $field['id'];
             $item['type'] = $field['type'];
             $item['label'] = isset($field['settings']['label']) ? $field['settings']['label'] : '';
             $item['placeholder'] = isset($field['settings']['placeholder']) ? $field['settings']['placeholder'] : null;
             $item['classname'] = isset($field['settings']['classname']) ? $field['settings']['classname'] : null;
             $item['required'] = isset($field['validations']['required']);
             $item['validations'] = isset($field['validations']) ? $field['validations'] : [];
             $item['html'] = '';
             // form values
             $values = isset($field['settings']['values']) ? $field['settings']['values'] : null;
             $defaultValues = isset($field['settings']['default_values']) ? $field['settings']['default_values'] : null;
             if ($field['type'] == 'dropdown') {
                 // values and labels are the same
                 $values = array_combine($values, $values);
                 // get index of selected item
                 $defaultIndex = array_search($defaultValues, $values, true);
                 if ($defaultIndex === false) {
                     $defaultIndex = null;
                 }
                 // create element
                 $ddm = $this->frm->addDropdown($item['name'], $values, $defaultIndex, false, $item['classname']);
                 // empty default element
                 $ddm->setDefaultElement('');
                 // add required attribute
                 if ($item['required']) {
                     $ddm->setAttribute('required', null);
                 }
                 $this->setCustomHTML5ErrorMessages($item, $ddm);
                 // get content
                 $item['html'] = $ddm->parse();
             } elseif ($field['type'] == 'radiobutton') {
                 // create element
                 $rbt = $this->frm->addRadiobutton($item['name'], $values, $defaultValues, $item['classname']);
                 // get content
                 $item['html'] = $rbt->parse();
             } elseif ($field['type'] == 'checkbox') {
                 // reset
                 $newValues = array();
                 // rebuild values
                 foreach ($values as $value) {
                     $newValues[] = array('label' => $value, 'value' => $value);
                 }
                 // create element
                 $chk = $this->frm->addMultiCheckbox($item['name'], $newValues, $defaultValues, $item['classname']);
                 // get content
                 $item['html'] = $chk->parse();
             } elseif ($field['type'] == 'textbox') {
                 // create element
                 $txt = $this->frm->addText($item['name'], $defaultValues, 255, $item['classname']);
                 // add required attribute
                 if ($item['required']) {
                     $txt->setAttribute('required', null);
                 }
                 if (isset($item['validations']['email'])) {
                     $txt->setAttribute('type', 'email');
                 }
                 if (isset($item['validations']['numeric'])) {
                     $txt->setAttribute('type', 'number');
                 }
                 if ($item['placeholder']) {
                     $txt->setAttribute('placeholder', $item['placeholder']);
                 }
                 $this->setCustomHTML5ErrorMessages($item, $txt);
                 // get content
                 $item['html'] = $txt->parse();
             } elseif ($field['type'] == 'datetime') {
                 // create element
                 if ($field['settings']['input_type'] == 'date') {
                     // calculate default value
                     $amount = $field['settings']['value_amount'];
                     $type = $field['settings']['value_type'];
                     if ($type != '') {
                         switch ($type) {
                             case 'today':
                                 $defaultValues = date('Y-m-d');
                                 // HTML5 input needs this format
                                 break;
                             case 'day':
                             case 'week':
                             case 'month':
                             case 'year':
                                 if ($amount != '') {
                                     $defaultValues = date('Y-m-d', strtotime('+' . $amount . ' ' . $type));
                                 }
                                 break;
                         }
                     }
                     // Convert the php date format to a jquery date format
                     $dateFormatShortJS = FrontendFormBuilderModel::convertPHPDateToJquery($this->get('fork.settings')->get('Core', 'date_format_short'));
                     $datetime = $this->frm->addText($item['name'], $defaultValues, 255, 'inputDatefield ' . $item['classname'])->setAttributes(array('data-mask' => $dateFormatShortJS, 'data-firstday' => '1', 'type' => 'date', 'default-date' => !empty($defaultValues) ? date($this->get('fork.settings')->get('Core', 'date_format_short'), strtotime($defaultValues)) : ''));
                 } else {
                     $datetime = $this->frm->addText($item['name'], $defaultValues, 255, $item['classname'])->setAttributes(array('type' => 'time'));
                 }
                 // add required attribute
                 if ($item['required']) {
                     $datetime->setAttribute('required', null);
                 }
                 $this->setCustomHTML5ErrorMessages($item, $datetime);
                 // get content
                 $item['html'] = $datetime->parse();
             } elseif ($field['type'] == 'textarea') {
                 // create element
                 $txt = $this->frm->addTextarea($item['name'], $defaultValues, $item['classname']);
                 $txt->setAttribute('cols', 30);
                 // add required attribute
                 if ($item['required']) {
                     $txt->setAttribute('required', null);
                 }
                 if ($item['placeholder']) {
                     $txt->setAttribute('placeholder', $item['placeholder']);
                 }
                 $this->setCustomHTML5ErrorMessages($item, $txt);
                 // get content
                 $item['html'] = $txt->parse();
             } elseif ($field['type'] == 'heading') {
                 $item['html'] = '<h3>' . $values . '</h3>';
             } elseif ($field['type'] == 'paragraph') {
                 $item['html'] = $values;
             } elseif ($field['type'] == 'submit') {
                 $item['html'] = $values;
             }
             // add to list
             $this->fieldsHTML[] = $item;
         }
     }
 }