public function onRender() { $settings = \Rafie\Contactform\Models\ContactFormSettings::instance(); $id = $this->property('formID'); $formTitle = $this->property('formTitle'); $form = Form::find($id); if (!$form) { Session::flash('error', true); Session::flash('messages', ['Form cannot be found.']); return; } // if $formHtml = ''; foreach ($form->fields as $field) { if ($field['objType'] == 'input' || $field['objType'] == 'upload') { $formComponent = new FormInput($field); } elseif ($field['objType'] == 'checkbox') { $formComponent = new FormCheckbox($field); } elseif ($field['objType'] == 'options') { $formComponent = new FormOptions($field); } elseif ($field['objType'] == 'paragraph') { $formComponent = new FormParagraph($field); } else { continue; } $formHtml .= $formComponent->render(); } // foreach $this->page['formTitle'] = isset($formTitle) ? $formTitle : $form->name; $this->page['formHtml'] = $formHtml; $this->page['form'] = $form; $this->page['mailTemplate'] = $this->property('mailTemplate'); $this->page['gCaptcha'] = isset($settings->google_captcha_disabled) && $settings->google_captcha_disabled === '0' ? false : $settings->google_captcha_key; $this->page['useBootstrap'] = $settings->use_bootstrap_css && $settings->use_bootstrap_css !== '0'; }
public function update_onSave() { $id = post('id'); if (!($model = Form::find($id))) { \Flash::error('Error while updating form!'); return; } //if $fields = sanitizeBoolean(post('fields', [])); $messages = post('messages', []); $model->name = post('name'); $model->fields = $fields; $model->messages = $messages; $model->save(); \Flash::success('Form updated successfully.'); return; }