This repository has been archived by the owner on Jul 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,8 @@ public function submit(Request $request) | |
{ | ||
$form = Form::findOrFail($request->id); | ||
|
||
$request->validate($this->buildValidation($form)); | ||
|
||
// Get $formData and $filesKeys verifying the MIME of files. | ||
$formDataAndFilesKeys = $this->getFormDataAndFilesKeys($form, $request); | ||
if($formDataAndFilesKeys instanceof RedirectResponse){ | ||
|
@@ -72,7 +74,7 @@ public function submit(Request $request) | |
if (empty($form->mailto)) { | ||
$form->mailto = !empty(setting('forms.default_to_email')) | ||
? setting('forms.default_to_email') | ||
: false; | ||
: '[email protected]'; | ||
} | ||
|
||
// The from address | ||
|
@@ -99,11 +101,9 @@ public function submit(Request $request) | |
// Debug/Preview the email | ||
// return (new EnquiryMailable($form, $formData, $filesKeys))->render(); | ||
|
||
// Send the email if enabled | ||
if ($form->mailto) { | ||
Mail::to(array_map('trim', explode(',', $form->mailto))) | ||
->send(new EnquiryMailable($form, $formData, $filesKeys)); | ||
} | ||
// Send the email | ||
Mail::to(array_map('trim', explode(',', $form->mailto))) | ||
->send(new EnquiryMailable($form, $formData, $filesKeys)); | ||
|
||
return redirect() | ||
->back() | ||
|
@@ -273,4 +273,30 @@ protected function getMimesFromForm($form){ | |
} | ||
return $mimes; | ||
} | ||
|
||
|
||
/** | ||
* Builds a validation array based on required / email input form fields. | ||
* Returns an array to be fed into the validate() function. | ||
* | ||
* @param Form $form | ||
* @return array $validationArray | ||
*/ | ||
protected function buildValidation($form) | ||
{ | ||
$validationArray = []; | ||
foreach ($form->inputs as $input) { | ||
if ($input->type === 'email') { | ||
$additionalValidation = '|email'; | ||
} else { | ||
$additionalValidation = ''; | ||
} | ||
|
||
if ($input->required) { | ||
$validationArray[$input->label] = 'required' . $additionalValidation; | ||
} | ||
} | ||
|
||
return $validationArray; | ||
} | ||
} |