Laravel 8 "not required" validation rule - laravel

how can I "tell" laravel that if the email field with validation rule 'email' and URL field (for example field where I expect the user to put his Facebook account link but that field IS NOT required) with validation rule 'URL' is not required and it is fine if it is empty. I have put nullable() on all database table columns but my validation rule still applies like it is required. Here are the parts of the code.
This is from migration:
$table->string('site_facebook')->nullable();
$table->string('site_instagram')->nullable();
$table->string('site_twitter')->nullable();
$table->string('site_linkedin')->nullable();
$table->string('site_behance')->nullable();
$table->string('site_dribbble')->nullable();
$table->string('site_email')->nullable();
This part is from validation:
'site_facebook' => 'url',
'site_facebook' => 'url',
'site_instagram' => 'url',
'site_twitter' => 'url',
'site_linkedin' => 'url',
'site_behance' => 'url',
'site_dribbble' => 'url',
'site_email' => 'email',
So, to wrap up my question. I want my URL and email fields to be optional not required :)
EDIT
Since there are some answers and no one work for me I just want to mention (if it does do anything with it), all of my validation rules are in a separate request...
class ManageSiteSettingsRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return [
'site_name' => 'required|max:50',
'site_facebook' => 'nullable|url',
'site_facebook' => 'url',
'site_instagram' => 'url',
'site_twitter' => 'url',
'site_linkedin' => 'url',
'site_behance' => 'url',
'site_dribbble' => 'url',
'site_email' => 'email',
'site_creator_link' => 'url',
];
}
}
This is the form:
#extends('layouts.admin')
#section('content')
<h2>Site settings</h2>
#include('includes._errors')
#include('includes._sessions')
<form action="{{ route('settings.update') }}" method="post">
#csrf
<div class="form-group">
<label for="site_name">Site name</label>
<input type="text" name="site_name" class="form-control" required placeholder="This field is required!" value="{{ $settings->site_name }}">
</div>
<div class="form-group">
<label for="site_description">Site description</label>
<textarea name="site_description" class="form-control mytinytext" id="site_description" cols="30" rows="10">{!! $settings->site_description !!}</textarea>
</div>
<div class="form-group">
<label for="site_facebook">Site facebook page</label>
<input type="text" name="site_facebook" class="form-control" placeholder="https://www.facebook.com/" value="{{ $settings->site_facebook }}">
</div>
<div class="form-group">
<label for="site_instagram">Site instagram page</label>
<input type="text" name="site_instagram" class="form-control" placeholder="https://www.instagram.com/" value="{{ $settings->instagram }}">
</div>
<div class="form-group">
<label for="site_twitter">Site twitter page</label>
<input type="text" name="site_twitter" class="form-control" placeholder="https://twitter.com/" value="{{ $settings->site_twitter }}">
</div>
<div class="form-group">
<label for="site_linkedin">Site linkedin page</label>
<input type="text" name="site_linkedin" class="form-control" placeholder="https://www.linkedin.com/" value="{{ $settings->site_linkedin }}">
</div>
<div class="form-group">
<label for="site_behance">Site behance page</label>
<input type="text" name="site_behance" class="form-control" placeholder="https://www.behance.net/" value="{{ $settings->site_behance }}">
</div>
<div class="form-group">
<label for="site_dribbble">Site dribbble page</label>
<input type="text" name="site_dribbble" class="form-control" placeholder="https://dribbble.com/" value="{{ $settings->site_dribbble }}">
</div>
<div class="form-group">
<label for="site_email">Site email</label>
<input type="text" name="site_email" class="form-control" placeholder="...#outlook... / ...#hotmail... / ...#gmail..." value="{{ $settings->site_email }}">
</div>
<hr class="divider">
<div class="form-group">
<label for="site_field_one">First footer field title</label>
<input type="text" name="site_field_one" class="form-control" placeholder="PHONE" value="{{ $settings->site_field_one }}">
</div>
<div class="form-group">
<label for="site_field_one_value">First footer field value</label>
<textarea name="site_field_one_value" id="site_field_one_value" class="mytinytext form-control" placeholder="+80 (0)5 22 55 66 77">{{ $settings->site_field_one_value }}</textarea>
</div>
<hr class="divider">
<div class="form-group">
<label for="site_field_two">Second footer field title</label>
<input type="text" name="site_field_two" class="form-control" placeholder="ADDRESS" value="{{ $settings->site_field_two }}">
</div>
<div class="form-group">
<label for="site_field_two_value">Second footer field value</label>
<textarea name="site_field_two_value" id="site_field_two_value" class="mytinytext form-control" placeholder="33 rue Burdeau 69089, Paris France">{{ $settings->site_field_two_value }}</textarea>
</div>
<hr class="divider">
<div class="form-group">
<label for="site_field_three">Third footer field title</label>
<input type="text" name="site_field_three" class="form-control" placeholder="ENQUIRUES" value="{{ $settings->site_field_three }}">
</div>
<div class="form-group">
<label for="site_field_three_value">Third footer field value</label>
<textarea name="site_field_three_value" id="site_field_three_value" class="mytinytext form-control" placeholder="email#gmail.com">{{ $settings->site_field_three_value }}</textarea>
</div>
<hr class="divider">
<div class="form-group">
<label for="site_field_four">Fourth footer field title</label>
<input type="text" name="site_field_four" class="form-control" placeholder="WORK HOURS" value="{{ $settings->site_field_four }}">
</div>
<div class="form-group">
<label for="site_field_four_value">Fourth footer field value</label>
<textarea name="site_field_four_value" id="site_field_four_value" class="mytinytext form-control" placeholder="Weekdays: 09:00 - 18:00 Weekends: 11:00 - 17:00">{{ $settings->site_field_four_value }}</textarea>
</div>
<hr class="divider">
<div class="form-group">
<label for="site_copyright">Site copyright</label>
<input type="text" name="site_copyright" class="form-control" placeholder="Created with love by _______ (fill 'Site creator name' field)" value="{{ $settings->site_copyright }}">
</div>
<hr class="divider">
<div class="form-group">
<label for="site_creator_name">Site creator name</label>
<input type="text" name="site_creator_name" class="form-control" placeholder="John Doe" value="{{ $settings->site_creator_name }}">
</div>
<div class="form-group">
<label for="site_creator_link">Site creator page</label>
<input type="text" name="site_creator_link" class="form-control" placeholder="https://site-creator-page.com" value="{{ $settings->site_creator_link }}">
</div>
<div class="form-group">
<button type="submit" name="btn_update_site_settings" class="btn btn-block btn-success">Update site settings</button>
</div>
</form>
#include('includes._errors')
#endsection

You can use nullable rule
Like the example below:
'site_facebook' => 'url|nullable',

Related

How to show a new column after using select2 in laravel?

I have a form and using select2 for filter. I want to show new column by using this select2.
I don't know its possible or not but i want to do this . using jquery or something, can someone reference to me about this? its my form for my input
<form class="form-prevent-multiple-submits" data-toggle="validator" action="{{route('update_sarpras_aduan'),'test'}} " method="post">
#csrf
{{method_field('patch')}}
<div class="form-group">
<label class="control-label" for="title">Nama Unit:</label>
<input type="text" name="nama_unit" id="nama_unit" class="form-control" data-error="Please enter title." required disabled/>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label" for="title">Tanggal Aduan:</label>
<textarea name="created_at" class="form-control" id="tgl_aduan" data-error="Please enter description." readonly ></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label" for="title">Nama Pengadu:</label>
<input type="text" name="nama_pengadu" class="form-control" id="nama_pengadu" data-error="Please enter title." readonly />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label> Isi Aduan </label>
<textarea name="aduan" id="aduan" class="form-control" rows="3" placeholder="Isi Aduan atau Keluhan ..." readonly ></textarea>
</div>
<div class="form-group">
<label class="control-label" for="title">Nama Teknisi:</label>
<input type="text" name="nama_teknisi" class="form-control" id="nama_teknisi" data-error="Please enter title." readonly />
<div class="help-block with-errors"></div>
</div>
----------------here this select2---------------------------
<div class="form-group">
<label>Pilih Inventaris</label>
<select class="form-control select2bs4" name="alat_id" id="alat_id" style="width: 100%;" aria-hidden="true">
#foreach($inven as $id => $item )
<option value="{{ $id }}">{{ $item }} </option>
#endforeach
</select>
</div>
--------------------------------------------------
<div class="form-group">
<label>Status Saat Ini (Jangan Lupa Diganti)</label>
<select name="status" id="status" class="form-control">
<option value="Tindakan Lanjutan">Tindakan Lanjutan</option>
<option value="Selesai">Selesai</option>
</select>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label> Tindakan Pelaksana </label>
<textarea name="tindakan" id="tindakan" class="form-control" rows="3" placeholder="Isi Tindakan Yang dilakukan" required ></textarea>
</div>
<div class="form-group">
<label>Kondisi Alat </label>
<select name="status_alat" id="status_alat" class="form-control">
<option value="Baik">Baik</option>
<option value="Rusak Ringan">Rusak Ringan</option>
<option value="Rusak Berat">Rusak Berat</option>
</select>
<div class="help-block with-errors"></div>
</div>
<input type="hidden" name="id" id="id" value="">
<input type="hidden" name="user_id" id="user_id" value="">
<input type="hidden" name="ipsrs_id" id="ipsrs_id" value="">
<input type="hidden" name="teknisi_id" id="teknisi_id" value="">
<input type="hidden" name="ended_at" id="ended_at" value="">
<div class="form-group">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="submit" id="button" class="btn btn-success crud-submit-edit button-prevent-multiple-submits">
<i class="spinner fa fa-spinner fa-spin" ></i>
Submit</button>
</div>
</form>
after using this select2 , will showing a new form . can someone references to me about this ?
//select input
<div class="form-group">
<label>Pilih Inventaris</label>
<select class="form-control select2bs4" name="alat_id" id="alat_id" style="width: 100%;" aria-hidden="true" onchange="Show()">
#foreach($inven as $id => $item )
<option value="{{ $id }}">{{ $item }} </option>
#endforeach
</select>
</div>
//new form
<div id="divid" style="display:none">
<form method="" action="">
#csrf
</form
<div>
//javascript code
<script>
function Show()
{
var fieldValue = $('#alat_id').val();
if(fieldValue == "")
{
document.getElementById("divid").style.display = 'none';
}
else{
document.getElementById("divid").style.display = 'inline'
}
}
</script>

How to solve this error in laravel "Name and email address are required if not a client"

I'm getting an error as "Name and email address are required if not a client" while running the below mentioned code.
Find below the Controller Code:
class UserController extends Controller
{
public function insertform(){
return view('test');
}
public function create(){
$user=Whmcs::AddClient([
'firstname' => Input::get('firstname'),
'lastname' => Input::get('lastname'),
'email' => Input::get('email'),
'address1' => Input::get('address1'),
'city' => Input::get('city'),
'state' => Input::get('state'),
'postcode' => Input::get('postcode'),
'country' => Input::get('country'),
'phonenumber' => Input::get('phonenumber'),
'password2' => Input::get('password2'),
]);
return $user;
}
}
Find below the route code:
Route::get('insert', 'UserController#insertform');
Route::post('create', 'UserController#create')->name('user.create');
The blade file is given below
<div id="content" class="app-content" role="main">
<div class="app-content-body ">
<div class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3">Sign up</h1>
</div>
<div class="wrapper-md" ng-controller="FormDemoCtrl">
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading font-bold">create an account</div>
<div class="panel-body">
<form class="bs-example form-horizontal" action="
{{route('user.create')}}" method="post">
<input type = "hidden" name = "_token" value = "<?php echo
csrf_token(); ?>">
<div class="form-group">
<label class="col-lg-2 control-label">firstname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="firstname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">lastname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="lastname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Email</label>
<div class="col-lg-6">
<input type="email" class="form-control" name="email"
placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">address1</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="address1"
placeholder="Subject">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">city</label>
<div class="col-lg-6">
<select class="form-control" name="city">
<option value="-- Select --">-- Select --</option>
<option value="Coimbatore">Coimbatore</option>
<option value="Chennai">Chennai</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">state</label>
<div class="col-lg-6">
<select class="form-control" name="state">
<option value="-- Select --">-- Select --</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Andhra">Andhra</option>
<option value="Karnataka">Karnataka</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">country</label>
<div class="col-lg-6">
<select class="form-control" name="country">
<option value="-- Select --">-- Select --</option>
<option value="India">India</option>
<option value="China">China</option>
<option value="Australia">Australia</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">postcode</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="postcode"
placeholder="postcode">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">phonenumber</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="phonenumber"
placeholder="phonenumber">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">password</label>
<div class="col-lg-6">
<input type="password" class="form-control" name="password2"
placeholder="password">
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-sm btn-
success">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
When I run the above code I'm getting an error as below:
{"result":"error","message":"Name and email address are required if not a client"}
suggest me a solution to solve this and post the data in laravel.

How to retrieve the post value and validate in controller using laravel?

In my route file
Route::get('griev_reg_form', 'GrievanceRegisterController#show');
Route::post('griev_reg_form', 'GrievanceRegisterController#postdata');
and in controller
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\GrievanceRegister;
use App\Department;
use Input;
use Validator;
use Redirect;
use Session;
class GrievanceRegisterController extends Controller
{
public function show()
{
$departments = Department::orderBy('edesc','ASC')->get();
return view('griev_reg_form', array('departments' => $departments));
}
public function postdata()
{
$data = Input::all();
// print_r($data);
echo $name = Input::get('name');
$rules = array(
'name' => 'required',
'email_address' => 'required|email',
'g-recaptcha-response' => 'required|captcha',
);
$validator = Validator::make($data, $rules);
if ($validator->fails()){
echo "1";
return Redirect::to('/griev_reg_form')->withInput()->withErrors($validator);
}
else{
// Do your stuff.
}
}
}
?>
and in the view file
{!! Form::open(array('url'=>'griev_reg_form','method'=>'POST', 'id'=>'myform')) !!}
<div class="box-body">
<div class="form-group">
<label class="col-sm-3 control-label">Grievance Case:
</label>
<label>
<input type="radio" name="gretype" class="minimal" checked>
</label>
<label>Normal Case
</label>
<label>
<input type="radio" name="gretype" class="minimal">
</label>
<label>
NRI
</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Grievance/Demand/Suggestion/Others:
</label>
<label>
<input type="radio" name="sugg_demand" class="minimal" checked value="G">
</label>
<label>Grievance
</label>
<label>
<input type="radio" name="sugg_demand" class="minimal" value="S">
</label>
<label>
Suggestion
</label>
<label>
<input type="radio" name="sugg_demand" class="minimal"
value="D">
</label>
<label>
Demand
</label>
<label>
<input type="radio" name="sugg_demand"
class="minimal" value="O">
</label>
<label>
Others
</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Department/Office:
</label>
<select class="form-control select2" name="dept_name" style="width: 28%;">
<option value="">Select Department</option>
<?php
foreach($departments as $result)
{
?>
<option value="<?php echo $result->deptcode; ?>"><?php echo $result->edesc; ?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Mobile No:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="mobileno">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Alternative Mobile No:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="amobileno">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Received Date:</label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control" name="recvd_date" id="datepicker" readonly="">
</div>
<!-- /.input group -->
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Name:</label>
<input type="text" class="form-control" name="cname">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Individual or Group Complainant(s):
</label>
<label>
<input type="radio" name="indiv_grp" value="I" class="minimal" checked>
</label>
<label>Individual
</label>
<label>
<input type="radio" name="indiv_grp" value="G" class="minimal">
</label>
<label>Group
</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">AADHAR Card Number:</label>
<input type="text" class="form-control" name="idproofdetail">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Address:</label>
<input type="text" class="form-control" name="address1">
</div>
<div class="form-group">
<input type="text" class="form-control box-right" name="address2">
</div>
<div class="form-group">
<input type="text" class="form-control box-right" name="address3">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Pin code:</label>
<input type="text" class="form-control" name="pincode">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Email:</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="email" class="form-control" placeholder="Email" name="email_address">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">District:
</label>
<select class="form-control select2" name="district_problem" style="width: 28%;">
</select>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">विधानसभा निर्वाचन क्षेत्र /Assembly Constituency:
</label>
<select class="form-control select2" name="ac_problem" style="width: 28%;">
</select>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Area:
</label>
<label>
<input type="radio" value="urban" name="problem_area" class="minimal" checked>
</label>
<label>Urban
</label>
<label>
<input type="radio" value="rural" name="problem_area" class="minimal">
</label>
<label>
Rural
</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Town/Block:
</label>
<select class="form-control select2" name="city_problem" style="width: 28%;">
</select>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Please Enter Specific Details about Your Grievance </label>
<textarea class="form-control" rows="3" name="Description" placeholder="Enter ..."></textarea>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">What do you want?</label>
<textarea class="form-control" rows="3" name="remedies" placeholder="Enter ..."></textarea>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Upload(Relevant Document):</label>
<input type="file" class="form-control">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Captcha</label>
<label class="col-sm-3 control-label">
{!! app('captcha')->display(); !!}
</label>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Submit
</button>
</div>
</div>
</form>
when i click on submit button without filling any data, its doesn't go
on validation part
Please provide help how can i check the post value of input fileds as well as
captcha and also validate accordingly
I have checked your view..I didnt find any input field named as "name", you have "cname" so maybe you validation rule should be:
$rules = array(
'cname' => 'required',
'email_address' => 'required|email',
'g-recaptcha-response' => 'required|captcha'
);
In case you are using >=5.3 version then you should use:
public function postdata(Request $request)
{
//validation
$validationArray = [
'cname' => 'required',
'email_address' => 'required|email',
'g-recaptcha-response' => 'required|captcha'
];
$validator = Validator::make($request->all(),$validationArray);
if ($validator->fails()) {
$response = ['errors' => $validator->messages()->all()];
return Response::json($response,200);
}
//here if validation is successful
}
Ofcourse add at top of controller: use Illuminate\Http\Request;

laravel form model binding not working laravel 5.4

I have gone through similar posts on SO but nothing has worked for me and also not found relative answer. Even it is not updating data.
{!! Form::model($editClient, [ 'method' => 'PATCH','route' => ['clients.update', $editClient->id],'class' => 'form-horizontal', 'id'=>'edit-client' ]) !!}
#include('clients._form')
I am using form as partial
Route:
Route::resource('clients', 'ClientController');
Controller Method:
public function edit($id)
{
$editClient = User::findOrFail($id);
return view('clients.edit', compact('editClient'));
}
HTML:
<div class="form-group">
<label class="control-label col-sm-2" for="username">Username:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="email" name="user_name" placeholder="Enter Username">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pwd" name="password" placeholder="Enter password">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="contact">Contact Number: </label>
<div class="col-sm-10">
<input type="number" class="form-control" id="contact" name="contact" placeholder="Enter Contact Number">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
From the Laravel Collective docs for Form model binding (https://laravelcollective.com/docs/5.4/html#form-model-binding):
{{ Form::model($user, ['route' => ['user.update', $user->id]]) }}
You have $editClient whereas I think your model is probably $client

Octobercms successful mail send returns empty alert

I am a newbie to Laravel and OctoberCMS.
I have successfully set up an info request form that sends me an email via Mailgun when submitted. Submission is handled by an AJAX handler.
The problem I have is that the process opens an alert box with an empty array on the form page.
Here is the page: http://imageweaversmarketing.com/
Click on 'CONTACT' in the top-right to move to the form.
Here is the partial with the form:
<div class="row">
<div class="col-lg-12">
<form data-request="onInfoRequest" name="sentMessage" id="contactForm" novalidate="">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required="" data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required="" data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required="" data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required="" data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl">
Send Message
</button>
</div>
</div>
</form>
</div>
Here is the PHP AJAX:
use Illuminate\Support\Facades\Mail;
public function onInfoRequest() {
$data = ['name' => 'test from function'];
Mail::send('mail.inforequest', $data, function ($message) {
$message->to('fake#hidden.com', 'Roger Creasy');
});
}
I appreciate any help.
I see you haven't used the data-request-success handler. That's necessary to show the output when mail is successful. Here's how I do it
function onSend()
{
// Collect input
$name = post('name');
$email = post('email');
// Form Validation
$validator = Validator::make(
[
'name' => $name,
'email' => $email
],
[
'name' => 'required',
'email' => 'required|email'
]
);
if ($validator->fails())
{
$messages = $validator->messages();
throw new ApplicationException($messages->first());
}
// All is well -- Submit form
$to = System\Models\MailSettings::get('sender_email');
$params = compact('name','email');
Mail::sendTo($to, 'temp.website::mail.newrequest', $params);
return true;
}
And on the form side I used
<form class="form-horizontal" data-request="onSend" data-request-success="alert('We have recieved your email.. we\'ll get back to you shortly')">
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-5">
<input id="name" name="name" type="text" placeholder="Name" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="email">Email</label>
<div class="col-md-5">
<input id="email" name="email" type="text" placeholder="Email ID" class="form-control input-md" required="">
</div>
</div>
</form>
So basically all you need is to add a data-request-success for it to work. Enjoy!
I had to get this completed. So, I gave up on a solution within October.
I am posting what I did as a workaround, in case it is helpful to someone else.
What I did is create a route resource, and direct it to a controller to handle the form. basically I went to the Laravel base structure and handled the form through its MVC.

Resources