Exemplo n.º 1
0
 /**
  * Save form data and send email
  * @param array $formData
  * @return bool|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function submission($formData)
 {
     if ($form_settings = $this->_block->getContent(true)) {
         $form_settings = $this->_defaultData($form_settings);
         $form_rules = BlockFormRule::get_rules($form_settings->template);
         $v = Validator::make($formData, $form_rules);
         $captcha = Securimage::captchaCheck();
         // check form rules
         if ($v->passes() && !($form_settings->captcha == true && !$captcha)) {
             // delete blank and system fields
             unset($formData['captcha_code']);
             // Save data function (override this function to save data differently)
             $form_submission = $this->submissionSaveData($formData);
             if (!$form_submission->id) {
                 FormMessage::add('submission_save_error', 'Unable to save the form.');
             }
             // Send email
             if ($this->submissionSendEmail($formData, $form_settings)) {
                 $form_submission->sent = 1;
                 $form_submission->save();
             }
             Session::set('form_data', $form_submission);
             return \redirect(PageBuilder::pageUrl($form_settings->page_to));
         } else {
             FormMessage::set($v->messages());
             if (!$captcha) {
                 FormMessage::add('captcha_code', 'Invalid Captcha Code, try again.');
             }
         }
     }
     return false;
 }
Exemplo n.º 2
0
 public static function updateFormRules()
 {
     if (!empty(self::$_formRules)) {
         BlockFormRule::import(self::$_formRules);
     }
 }
 public function postForms($template)
 {
     $databaseRules = [];
     $inputRules = [];
     $rules = BlockFormRule::where('form_template', '=', $template)->get();
     if (!$rules->isEmpty()) {
         foreach ($rules as $rule) {
             $databaseRules[$rule->field] = $rule;
         }
     }
     $rules = Request::get('rule');
     if (!empty($rules)) {
         foreach ($rules as $rule) {
             $inputRules[$rule['field']] = $rule['rule'];
         }
     }
     $toAdd = array_diff_key($inputRules, $databaseRules);
     $toUpdate = array_intersect_key($inputRules, $databaseRules);
     $toDelete = array_diff_key($databaseRules, $inputRules);
     if (!empty($toDelete)) {
         BlockFormRule::where('form_template', '=', $template)->whereIn('field', array_keys($toDelete))->delete();
     }
     if (!empty($toAdd)) {
         foreach ($toAdd as $field => $rule) {
             $newBlockFormRule = new BlockFormRule();
             $newBlockFormRule->form_template = $template;
             $newBlockFormRule->field = $field;
             $newBlockFormRule->rule = $rule;
             $newBlockFormRule->save();
         }
     }
     if (!empty($toUpdate)) {
         foreach ($toUpdate as $field => $rule) {
             if ($rule != $databaseRules[$field]->rule) {
                 $databaseRules[$field]->rule = $rule;
                 $databaseRules[$field]->save();
             }
         }
     }
     return \redirect()->route('coaster.admin.themes.forms');
 }
Exemplo n.º 4
0
 /**
  * Repeater form submission
  * @param array $formData
  * @return null|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function submission($formData)
 {
     $formRules = BlockFormRule::get_rules($this->_block->name . '-form');
     $v = Validator::make($formData, $formRules);
     if ($v->passes()) {
         foreach ($formData as $blockName => $content) {
             $fieldBlock = Block::preload($blockName);
             if ($fieldBlock->exists) {
                 if ($fieldBlock->type == 'datetime' && empty($content)) {
                     $content = new Carbon();
                 }
                 $formData[$blockName] = $content;
             }
         }
         $this->insertRow($formData);
         Email::sendFromFormData([$this->_block->name . '-form'], $formData, config('coaster::site.name') . ': New Form Submission - ' . $this->_block->label);
         return \redirect(Request::url());
     } else {
         FormMessage::set($v->messages());
     }
     return null;
 }