Skip to content

Instantly share code, notes, and snippets.

@daugaard47
Created December 5, 2020 23:46
Show Gist options
  • Save daugaard47/c3fcac4b42cae29f2052ed5c79c51dba to your computer and use it in GitHub Desktop.
Save daugaard47/c3fcac4b42cae29f2052ed5c79c51dba to your computer and use it in GitHub Desktop.
Regular Laravel Honey Package

I still get the @once @endonce redering on the page. I've cleared the catch every possible way I know how..

Link to screenshot of form https://imgur.com/jALbkNk

<form action="{{ route('submitInquireHome') }}" method="POST"
class="mt-4 grid sm:grid-cols-2 grid-cols-1 gap-2">
@csrf
<div class="sm:col-span-2 col-span-1">
<label for="group_type" class="sr-only block text-sm leading-5 font-medium text-gray-700">Select your group type
<x-required-dot/>
</label>
<select id="group_type" name="group_type"
class="mt-1 text-gray-400 focus:text-gray-600 active:text-gray-600 visited:text-gray-600 form-select block w-full pl-3 pr-10 py-2 text-base leading-6 border-gray-300 focus:outline-none focus:shadow-outline-blue focus:border-blue-300 sm:text-sm sm:leading-5">
<option selected disabled>Please Select Your Group Type</option>
<option value="Individual" {{ old('group_type') == 'Individual' ? 'selected' : '' }}>Individual</option>
<option value="Family" {{ old('group_type') == 'Family' ? 'selected' : '' }}>Family</option>
<option value="Group" {{ old('group_type') == 'Group' ? 'selected' : '' }}>Group (2-9 people)</option>
<option value="Team Leader" {{ old('group_type') == 'Team Leader' ? 'selected' : '' }}>Team Leader (10+ people)</option>
</select>
</div>
<div class="col-span-1">
<label for="first_name"
class="sr-only block text-sm font-medium leading-5 capitalize text-bh-navy-600">
First name
<x-required-dot/>
</label>
<div class="mt-1 rounded-md shadow-sm">
@guest
<input id="first_name" name="first_name" type="text"
placeholder="First Name"
value="{{ old('first_name') }}" required
class="{{ $errors->has('first_name') ? ' border border-red-500' : '' }} form-input block w-full focus:shadow-outline-gray focus:border-bh-navy-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"/>
@else
<input id="first_name" name="first_name" type="text"
placeholder="First Name"
value="{{ ucfirst(strtolower($user->first_name)) }}" required
class="{{ $errors->has('first_name') ? ' border border-red-500' : '' }} form-input block w-full focus:shadow-outline-gray focus:border-bh-navy-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"/>
@endguest
</div>
@if ($errors->has('first_name'))
<span class="appearance-none invalid-feedback">
<strong class="text-sm text-bh-red-500 font-normal italic">{{ $errors->first('first_name') }}</strong>
</span>
@endif
</div>
<div class="col-span-1">
<label for="last_name"
class="sr-only block text-sm font-medium leading-5 capitalize text-bh-navy-600">
Last name
<x-required-dot/>
</label>
<div class="mt-1 rounded-md shadow-sm">
@guest
<input id="last_name" name="last_name" type="text"
placeholder="Last Name"
value="{{ old('last_name') }}" required
class="{{ $errors->has('last_name') ? ' border border-red-500' : '' }} form-input block w-full focus:shadow-outline-gray focus:border-bh-navy-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"/>
@else
<input id="last_name" name="last_name" type="text"
placeholder="Last Name"
value="{{ ucfirst(strtolower($user->last_name)) }}" required
class="{{ $errors->has('last_name') ? ' border border-red-500' : '' }} form-input block w-full focus:shadow-outline-gray focus:border-bh-navy-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"/>
@endguest
</div>
@if ($errors->has('last_name'))
<span class="appearance-none invalid-feedback">
<strong class="text-sm text-bh-red-500 font-normal italic">{{ $errors->first('last_name') }}</strong>
</span>
@endif
</div>
<div class="sm:col-span-1">
<label for="email"
class="sr-only block text-sm font-medium leading-5 capitalize text-bh-navy-600">
Email address
<x-required-dot/>
</label>
<div class="mt-1 rounded-md shadow-sm">
@guest
<input id="email" name="email" type="email"
placeholder="Email Address"
value="{{ old('email') }}" required
class="{{ $errors->has('email') ? ' border border-red-500' : '' }} form-input block w-full focus:shadow-outline-gray focus:border-bh-navy-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"/>
@else
<input id="email" name="email" type="email"
placeholder="Email Address"
value="{{ ucfirst(strtolower($user->email)) }}" required
class="{{ $errors->has('email') ? ' border border-red-500' : '' }} form-input block w-full focus:shadow-outline-gray focus:border-bh-navy-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"/>
@endguest
</div>
@if ($errors->has('email'))
<span class="appearance-none invalid-feedback">
<strong class="text-sm text-bh-red-500 font-normal italic">{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class="sm:col-span-1">
<label for="phone"
class="sr-only block text-sm font-medium leading-5 capitalize text-bh-navy-600">
Phone
<x-required-dot/>
</label>
<div class="mt-1 rounded-md shadow-sm">
@guest
<input id="phone" name="phone" type="tel"
placeholder="Phone Number"
value="{{ old('phone') }}" required
class="{{ $errors->has('phone') ? ' border border-red-500' : '' }} form-input block w-full focus:shadow-outline-gray focus:border-bh-navy-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"/>
@else
<input id="phone" name="phone" type="tel"
placeholder="Phone Number"
value="{{ ucfirst(strtolower($user->phone)) }}" required
class="{{ $errors->has('phone') ? ' border border-red-500' : '' }} form-input block w-full focus:shadow-outline-gray focus:border-bh-navy-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"/>
@endguest
</div>
@if ($errors->has('phone'))
<span class="appearance-none invalid-feedback">
<strong class="text-sm text-bh-red-500 font-normal italic">{{ $errors->first('phone') }}</strong>
</span>
@endif
</div>
<div class="sm:col-span-2 col-span-1">
<div x-data="{ open: false }">
<label for="location_of_interest"
class="sr-only block text-sm leading-5 font-medium text-gray-700">Countries of interest
<x-required-dot/>
</label>
{{-- @click.away="open = false"--}}
<div x-on:click="open = true"
class="mt-1 flex bg-white form-select text-gray-400 focus:text-gray-600 block rounded shadow-sm border border-gray-300 cursor-pointer">Select Your Countries Of Interest
</div>
<div x-show.transition="open" @click.away="open = false" x-cloak
class="-mt-1 flex bg-white py-3 px-4 rounded-b shadow-sm border border-gray-300">
<div class="grid lg:grid-cols-4 md:grid-cols-3 sm:grid-cols-3 grid-cols-2 gap-3">
@foreach($activeCountries as $activeCountry)
<div class="flex items-center col-span-1">
<input id="location_of_interest" name="location_of_interest[]"
value="{{ $activeCountry->name }}"
{{ (is_array(old('location_of_interest')) && in_array($activeCountry->name, old('location_of_interest'))) ? ' checked' : '' }} type="checkbox"
class="form-checkbox h-4 w-4 text-gray-600 transition duration-150 ease-in-out">
<label for="location_of_interest" class="ml-2 block text-sm leading-5 text-gray-900">
{{ $activeCountry->name }}
</label>
</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="sm:col-span-2 col-span-1">
<div class="flex justify-between">
<label for="comments"
class="sr-only text-sm font-medium leading-5 text-bh-navy-700">Tell us more about yourself</label>
</div>
<div class="mt-1 relative rounded shadow-sm">
<textarea id="comments" name="comments" rows="4"
placeholder="Tell Us More About Yourself | Optional"
class="form-textarea block w-full transition ease-in-out duration-150 sm:text-sm sm:leading-5">{{ old('comments') }}</textarea>
</div>
</div>
<!--ADD HONEYPOT PACKAGE-->
<x-honey recaptcha="homePageForm"/>
<!--END HONEYPOT PACKAGE-->
<div class="text-right sm:col-span-2 col-span-1">
<span class="inline-flex rounded shadow-sm">
<button type="submit"
class="inline-flex justify-center py-2 px-4 border border-transparent text-sm leading-5 font-medium rounded text-white bg-bh-navy-600 hover:bg-bh-navy-500 focus:outline-none focus:border-bh-navy-700 focus:shadow-outline-bh-gray active:bg-bh-navy-700 transition duration-150 ease-in-out">
Submit
</button>
</span>
</div>
</form>
<?php
namespace App\Http\Controllers\Email\TripInquire;
use App\Http\Controllers\Controller;
use App\Mail\TripInquire\Staff\TripInquireHomeEmail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
class TripInquireHomeFormController extends Controller
{
public function submitInquireHome(Request $request)
{
$validatedData = $request->validate([
'group_type' => 'required',
'first_name' => 'required|min:2',
'last_name' => 'required|min:2',
'email' => 'required|string|email|max:255',
'phone' => 'required|min:7',
'comments' => 'nullable|min:2',
// 'location_of_interest' => 'nullable',
// 'g-recaptcha-response' => 'required|captcha',
]);
// Take the array of the other_locations_of_interest and converts to a comma separated list.
if ($request->input('location_of_interest')) {
$location_of_interest_string = '';
foreach ($request->input('location_of_interest') as $convertToComma) {
$location_of_interest_string .= $convertToComma . ', ';
}
$location_of_interest = substr($location_of_interest_string, 0, -1);
$mailTo = '[email protected]';
Mail::to($mailTo)->bcc('[email protected]')
->send(new TripInquireHomeEmail(
$request->input('group_type'),
$request->input('first_name'),
$request->input('last_name'),
$request->input('email'),
$request->input('phone'),
$request->input('comments'),
$location_of_interest
));
} else {
$mailTo = '[email protected]';
Mail::to($mailTo)->bcc('[email protected]')
->send(new TripInquireHomeEmail(
$request->input('group_type'),
$request->input('first_name'),
$request->input('last_name'),
$request->input('email'),
$request->input('phone'),
$request->input('comments'),
null
));
}
return back()->with('success', 'Your inquiry has been sent. We will be in contact with you soon.');
}
}
Route::post('/submit-inquire-home', 'TripInquireHomeFormController@submitInquireHome')
->middleware(['honey', 'honey-recaptcha'])
->name('submitInquireHome');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment