Exemplo n.º 1
0
 public function onSaveForm()
 {
     $settings = \Rafie\Contactform\Models\ContactFormSettings::instance();
     $request = \App::make('request');
     if ($settings->google_captcha_disabled == '1' && !$this->hasGoogleCaptcha($request)) {
         return Redirect::back()->with(['error' => true, 'messages' => ['Re-captcha is not set! Are you a Robot?']]);
     }
     $data = $this->cleanRequestData($request->all());
     $form = Form::findOrFail($data['fid']);
     $rules = $this->buildValidationRules($form->fields);
     $customMessages = $this->buildCustomValidationMessages($form->messages);
     $messages = $this->isValidUserInput($data, $rules, $customMessages);
     if ($messages !== true) {
         return Redirect::back()->with(['error' => true, 'messages' => $messages]);
     }
     $this->saveAttachments($data);
     // save user submission
     $mailTemplate = Email::find($data['tid']);
     $userForm = new UserForm();
     $userForm->form_id = $form->id;
     $userForm->fields = json_encode($data);
     $userForm->request_headers = json_encode($request->server->all());
     $userForm->save();
     // fire event to send emails
     Event::fire('RAFIE.FormPosted', [$userForm, $mailTemplate]);
     // redirect with success
     return Redirect::to('message-success');
 }
Exemplo n.º 2
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;
 }