public function destroy($form_slug, $field_slug) { $form = Form::where('slug', $form_slug)->firstOrFail(); $field = $form->fields()->where('slug', $field_slug)->firstOrFail(); $field->delete(); return redirect()->route('admin.forms.edit', $form->slug)->with('message', trans('field.message.delete_success')); }
/** * Show the form responses for a given slug. * * @param string $slug * @return Response */ public function responses($slug) { die('@TODO: Not working yet.'); $form = \App\Form::where('slug', '=', $slug)->firstOrFail(); $responses = \App\Response::where('form_id', '=', $form->id)->get(); return view('forms.responses', array('fields' => $form->fields, 'responses' => $responses)); }
public function getRecordArray(Request $request) { $id = $request->id; $rid = RecordPreset::where('id', '=', $id)->first()->rid; $record = Record::where('rid', '=', $rid)->first(); $form = Form::where('fid', '=', $record->fid)->first(); $field_collect = $form->fields()->get(); $field_array = array(); foreach ($field_collect as $field) { $data = array(); $data['flid'] = $field->flid; $data['type'] = $field->type; if ($field->type == 'Text') { $textfield = TextField::where('rid', '=', $record->rid)->first(); $data['text'] = $textfield->text; $flid_array[] = $field->flid; } elseif ($field->type == 'Rich Text') { $rtfield = RichTextField::where('rid', '=', $record->rid)->first(); $data['rawtext'] = $rtfield->rawtext; $flid_array[] = $field->flid; } elseif ($field->type == 'Number') { $numberfield = NumberField::where('rid', '=', $record->rid)->first(); $data['number'] = $numberfield->number; $flid_array[] = $field->flid; } elseif ($field->type == 'List') { $listfield = ListField::where('rid', '=', $record->rid)->first(); $data['option'] = $listfield->option; $flid_array[] = $field->flid; } elseif ($field->type == 'Multi-Select List') { $mslfield = MultiSelectListField::where('rid', '=', $record->rid)->first(); $data['options'] = explode('[!]', $mslfield->options); $flid_array[] = $field->flid; } elseif ($field->type == 'Generated List') { $gnlfield = GeneratedListField::where('rid', '=', $record->rid)->first(); $data['options'] = explode('[!]', $gnlfield->options); $flid_array[] = $field->flid; } elseif ($field->type == 'Date') { $datefield = DateField::where('rid', '=', $record->rid)->first(); $date_array['circa'] = $datefield->circa; $date_array['era'] = $datefield->era; $date_array['day'] = $datefield->day; $date_array['month'] = $datefield->month; $date_array['year'] = $datefield->year; $data['data'] = $date_array; $flid_array[] = $field->flid; } elseif ($field->type == 'Schedule') { $schedfield = ScheduleField::where('rid', '=', $record->rid)->first(); $data['events'] = explode('[!]', $schedfield->events); $flid_array[] = $field->flid; } $field_array[$field->flid] = $data; } $response['data'] = $field_array; $response['flids'] = $flid_array; return $response; }
public function postSelected(Request $request, $form_code) { $randomCode = Auth::id() . mt_rand(0, 999) . time(); $form = Form::where('form_code', $form_code)->where('form_type', 'template')->where('form_active', '1')->firstOrFail(); $form->update(['form_copy' => $form->form_copy + 1]); $formCopy = Form::create(['form_cuid' => Auth::id(), 'form_type' => 'normal', 'form_code' => $randomCode, 'form_active' => 0, 'form_title' => $form->form_title, 'form_summary' => $form->form_summary, 'form_sort' => 0, 'form_url' => $randomCode, 'form_tips_email' => 0, 'form_limit_auz' => 'allow_all']); foreach ($form->Field()->get() as $field) { $fieldCopy = Field::create(['field_cuid' => Auth::id(), 'field_form_id' => $formCopy->form_id, 'field_sort' => $field->field_sort, 'field_type' => $field->field_type, 'field_title' => $field->field_title, 'field_tips' => $field->field_tips, 'field_attr_name' => Auth::id() . mt_rand(0, 999) . time() . mt_rand(0, 999), 'field_attr_value' => $field->field_attr_value, 'field_attr_width' => $field->field_attr_width, 'field_must' => $field->field_must]); foreach ($field->FieldChildren()->get() as $fieldchildren) { FieldChildren::create(['fieldchildren_field_id' => $fieldCopy->field_id, 'fieldchildren_key' => $fieldchildren->fieldchildren_key, 'fieldchildren_value' => $fieldchildren->fieldchildren_value, 'fieldchildren_value2' => $fieldchildren->fieldchildren_value2, 'fieldchildren_value3' => $fieldchildren->fieldchildren_value3, 'fieldchildren_img_id' => $fieldchildren->fieldchildren_img_id, 'fieldchildren_checked' => $fieldchildren->fieldchildren_checked, 'fieldchildren_disabled' => $fieldchildren->fieldchildren_disabled]); } } $res = redirect('/form/info/' . $formCopy->form_code)->with('msgSuccess', '此表单模板已经添加到您的表单中心当中'); return $res; }
public function search(Request $request) { $input = Request::all(); $users = User::all(); $sort = 'new'; $forms = Form::where('tag', $input['tag'])->get(); return view('welcome', compact('forms', 'users', 'sort')); }
public function destroy($slug) { $form = Form::where('slug', $slug)->firstOrFail(); $form->delete(); return redirect()->route('admin.forms.index')->with('message', trans('form.message.delete_success')); }
public function index($form_slug) { $form = Form::where('slug', $form_slug)->firstOrFail(); $submissions = $form->submissions()->orderBy('created_at', 'desc')->paginate(20); return view('admin.submissions.index', ['form' => $form, 'submissions' => $submissions]); }
public function destroyform($id) { $audit_form = AuditTemplateForm::findOrFail($id); FormFormula::where('form_id', $audit_form->form_id)->delete(); FormCondition::where('form_id', $audit_form->form_id)->delete(); FormMultiSelect::where('form_id', $audit_form->form_id)->delete(); FormSingleSelect::where('form_id', $audit_form->form_id)->delete(); $audit_form->delete(); Form::where('id', $audit_form->form_id)->delete(); Session::flash('flash_message', 'Template form succesfully deleted!'); return redirect()->route("audittemplate.form", $audit_form->audit_template_id); }
public function postDel(Request $request, $form_code) { $form = Form::where('form_code', '=', $form_code)->where('form_type', 'template')->firstOrFail(); //删除 fields 和 fieldchildrens $fields = $form->Field(); foreach ($fields->get() as $field) { $field->FieldChildren()->forceDelete(); } $fields->forceDelete(); //删除 results 和 ResultRow $results = $form->Result(); foreach ($results->get() as $result) { $result->ResultRow()->forceDelete(); } $results->forceDelete(); //删除form 关联的 img $img = $form->Img_thumbnail()->first(); if ($img) { $img->decouple(); } //删除form $form->forceDelete(); $res = ['response' => 'YES', 'status' => 1]; return response()->json($res); }
public function testRedirectAfterSubmission() { $form = Form::where('slug', 'test-with-redirect')->firstOrFail(); $this->call('POST', '/forms/' . $form->slug); $this->assertRedirectedTo($form->redirect_to_url); }
private function addPresets(Form $form, $fid) { $preset = Form::where('fid', '=', $fid)->first(); $field_assoc = array(); $form->layout = $preset->layout; foreach ($preset->fields()->get() as $field) { $new = new Field(); $new->pid = $form->pid; $new->fid = $form->fid; $new->order = $field->order; $new->type = $field->type; $new->name = $field->name; $new->slug = $field->slug . '_' . $form->slug; $new->desc = $field->desc; $new->required = $field->required; $new->default = $field->default; $new->options = $field->options; $new->save(); $field_assoc[$field->flid] = $new->flid; } $xmlArray = FormController::xmlToArray($form->layout); for ($i = 0; $i < sizeof($xmlArray); $i++) { if ($xmlArray[$i]['tag'] == 'ID') { $temp = $field_assoc[$xmlArray[$i]['value']]; $xmlArray[$i]['value'] = $temp; } } $x = new FieldNavController(); $xmlString = $x->valsToXML($xmlArray); $form->layout = $xmlString; $form->save(); }
public function postDel(Request $request, $form_code) { $form = Form::where('form_cuid', '=', Auth::id())->where('form_code', '=', $form_code)->where('form_type', 'normal')->firstOrFail(); //删除 fields 和 fieldchildrens $fields = $form->Field(); foreach ($fields->get() as $field) { $field->FieldChildren()->forceDelete(); } $fields->forceDelete(); //删除 results 和 ResultRow $results = $form->Result(); foreach ($results->get() as $result) { $result->ResultRow()->forceDelete(); } $results->forceDelete(); //删除form $form->forceDelete(); $res = ['response' => 'YES', 'status' => 1]; return response()->json($res); }
public function store($form_slug, Request $request) { $form = Form::where('slug', $form_slug)->firstOrFail(); if (!$form->accept_submissions) { return response()->view('submissions.closed', [], 403); } $fields = $form->fields; $rules = $fields->pluck('rules', 'slug')->toArray(); $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return response()->view('submissions.errors', ['messages' => $validator->errors()], 422); } DB::beginTransaction(); $submission = new Submission(); $submission->user_ip = $request->ip(); $submission->user_agent = $request->server('HTTP_USER_AGENT'); $submission->user_referer = $request->server('HTTP_REFERER'); $form->submissions()->save($submission); foreach ($fields as $field) { $value = $request->get($field->slug, null); // Do not store null or non-given values if (is_null($value)) { continue; } $submission->fields()->save($field, ['value' => $value]); } DB::commit(); if (!is_null($form->send_email_to)) { $send_to = explode(',', $form->send_email_to); foreach ($send_to as $email) { Mail::send('emails.notification', ['submission' => $submission], function ($message) use($email, $form) { $message->from($form->owner_email, is_null($form->owner_name) ? $form->owner_email : $form->owner_name); $message->to($email); $message->subject(trans('submission.heading.new_submission_on', ['form' => $form->title])); }); } } /** * This var will hold the email confirmation status * null: Nothing happened about confirmation * true: Email sent * false: Tried to send email but error occurred */ $email_sent_successfully = null; if (!is_null($form->confirmation_message)) { $email_sent_successfully = false; // From now defaults to false $email_field = $form->fields()->where('slug', $form->confirmation_email_field)->first(); if (is_null($email_field)) { Log::error('Confirmation email not sent : Invalid field "' . $form->confirmation_email_field . '" for form "' . $form->slug . '"'); } else { $email = $submission->field($email_field)->pivot->value; $email_validator = Validator::make(['email' => $email], ['email' => 'required|email']); if ($email_validator->fails()) { Log::error('Confirmation email not sent : Invalid email address "' . $email . '" in field "' . $email_field->slug . '" of submission ' . $submission->id . ' on form "' . $form->slug . '"'); } else { $parsedown = new \Parsedown(); $html_message = $parsedown->text($form->confirmation_message); $html_message = preg_replace_callback('/\\:([0-9a-z_-]+)\\b/i', function ($matches) use($submission) { $field = $submission->fields->where('slug', $matches[1])->first(); if (!is_null($field)) { return e($field->pivot->value); } return ':' . $matches[1]; }, $html_message); Mail::send('emails.confirmation', ['html_message' => $html_message, 'submission' => $submission], function ($message) use($email, $form) { $message->from($form->owner_email, is_null($form->owner_name) ? $form->owner_email : $form->owner_name); $message->to($email); $message->subject(trans('submission.heading.submitted')); }); $email_sent_successfully = true; } } } /** * Redirect the user to the configurer url, but not if an error occurred */ if ($email_sent_successfully !== false && !is_null($form->redirect_to_url)) { return redirect($form->redirect_to_url); } return response()->view('submissions.submitted', ['email_sent_successfully' => $email_sent_successfully], 201); }