我一直试图通过表单上的POST发送我的电子邮件。我正在使用Laravel,它收到错误emp_1_start is not defined
。谁能告诉我哪里出错了?我使用相同的方法发送另一个表单。
34923b604b75ce6af5608d80e0c0cfda第15行中的ErrorException:
未定义 变量:emp_1_start
(查看: /home/fujita/ef/resources/views/emails/submitApplication.blade.php)
function formSubmit(){
$(".step a.btn.next, .submit").on('click', function(e){
var id = $(this).attr('data-id'),
bar = $('.bar'),
messages = $('.messages'),
html = $('html'),
// over = $('.overlay'),
form = $(this).closest('form'),
curStep = $(this).closest('.step').attr('data-id'),
data = form.serializeArray(),
route = window.location.pathname;
e.preventDefault();
bar.removeClass('error');
html.removeClass('m-active');
messages.find('ul > li').remove();
$.ajax({
url: route,
type: 'POST',
data: data,
dataType: 'JSON',
success: function (data) {
var pass = data['pass'];
if(!pass){
// TODO: Add icon to let user know there is an error
$.each(data.ivInputs, function(index, item){
$('.' + item).next('.bar').addClass('error');
});
$.each(data['message'], function(index, item){
$('.messages ul').append('<li>' + item + '</li>');
});
html.addClass('m-active');
} else {
if(id == 5){
$('.progress').addClass('remove');
}
$('.step, .dot').removeClass('current');
$('.dot[data-id=step' + (id - 1) + ']').addClass('success');
$('.step[data-id=step' + id + '], .dot[data-id=step' + id + ']').addClass('current');
}
}
});
});
}
public function submitApplication(Request $request){
$input = $request->all();
$rules = [];
switch ($input['formStep']) {
case 'step1':
$rules = [
'name' => 'required|regex:/^[a-zA-Z\s]*$/',
'email' => 'required|email',
'phone' => 'required|regex:/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/',
'age_above_18_yn' => 'required',
// 'age_above_18_yes' => 'required'
];
break;
case 'step2':
$rules = [
'emp_1_start' => 'required',
'emp_1_end' => 'required',
'emp_1_title' => 'required',
'emp_1_salary' => 'required',
'emp_1_sup_name' => 'required|regex:/^[a-zA-Z\s]*$/',
'emp_1_sup_phone' => 'required|regex:/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/',
'emp_1_duties' => 'required',
'emp_2_start' => 'required',
'emp_2_end' => 'required',
'emp_2_title' => 'required',
'emp_2_salary' => 'required',
'emp_2_sup_name' => 'required|regex:/^[a-zA-Z\s]*$/',
'emp_2_sup_phone' => 'required|regex:/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/',
'emp_2_duties' => 'required',
'emp_3_start' => 'required',
'emp_3_end' => 'required',
'emp_3_title' => 'required',
'emp_3_salary' => 'required',
'emp_3_sup_name' => 'required|regex:/^[a-zA-Z\s]*$/',
'emp_3_sup_phone' => 'required|regex:/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/',
'emp_3_duties' => 'required'
];
break;
case 'step3':
$rules = [
'ref_1_name' => 'required|regex:/^[a-zA-Z\s]*$/',
'ref_1_phone' => 'required|regex:/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/',
'ref_1_relationship' => 'required',
'ref_2_name' => 'required|regex:/^[a-zA-Z\s]*$/',
'ref_2_phone' => 'required|regex:/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/',
'ref_2_relationship' => 'required',
'ref_3_name' => 'required|regex:/^[a-zA-Z\s]*$/',
'ref_3_phone' => 'required|regex:/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/',
'ref_3_relationship' => 'required'
];
break;
case 'step4':
$rules = [
'availability' => 'required',
'commitments' => 'required',
'hear_about_us' => 'required',
// 'comments' => 'required'
];
break;
default:
# code...
break;
}
$messages = [
'name.required' => 'The Name Field is Required',
'email.required' => 'The Email Field is Required',
'phone.required' => 'The Phone Field is Required',
'age_above_18_yn.required' => 'The Are You Above 18 Field is Required',
// 'age_above_18_yes.required' => 'The Optional',
'emp_1_start.required' => 'Employer 1 Start Date Field is Required',
'emp_1_end.required' => 'Employer 1 End Date Field is Required',
'emp_1_title.required' => 'Employer 1 End Date Field is Required',
'emp_1_salary.required' => 'Employer 1 Salary Field is Required',
'emp_1_sup_name.required' => 'Employer 1 Supervisor Name Field is Required',
'emp_1_sup_phone.required' => 'The Employer 1 Supervisor Phone Number Field is Required',
'emp_1_duties.required' => 'Employer 1 List of Duties Field is Required',
'emp_2_start.required' => 'Employer 2 Start Date Field is Required',
'emp_2_end.required' => 'Employer 2 End Date Field is Required',
'emp_2_title.required' => 'Employer 2 End Date Field is Required',
'emp_2_salary.required' => 'Employer 2 Salary Field is Required',
'emp_2_sup_name.required' => 'Employer 2 Supervisor Name Field is Required',
'emp_2_sup_phone.required' => 'The Employer 2 Supervisor Phone Number Field is Required',
'emp_2_duties.required' => 'Employer 2 List of Duties Field is Required',
'emp_3_start.required' => 'Employer 3 Start Date Field is Required',
'emp_3_end.required' => 'Employer 3 End Date Field is Required',
'emp_3_title.required' => 'Employer 3 End Date Field is Required',
'emp_3_salary.required' => 'Employer 3 Salary Field is Required',
'emp_3_sup_name.required' => 'Employer 3 Supervisor Name Field is Required',
'emp_3_sup_phone.required' => 'The Employer 3 Supervisor Phone Number Field is Required',
'emp_3_duties.required' => 'Employer 3 List of Duties Field is Required',
'ref_1_name.required' => 'The Reference 1 Name Field is Required',
'ref_1_phone.required' => 'The Reference 1 Phone Number Field is Required',
'ref_1_relationship.required' => 'The Reference 1 Relationship Field is Required',
'ref_1_name.required' => 'The Reference 2 Name Field is Required',
'ref_1_phone.required' => 'The Reference 2 Phone Number Field is Required',
'ref_1_relationship.required' => 'The Reference 2 Relationship Field is Required',
'ref_3_name.required' => 'The Reference 3 Name Field is Required',
'ref_3_phone.required' => 'The Reference 3 Phone Number Field is Required',
'ref_3_relationship.required' => 'The Reference 3 Relationship Field is Required',
'availability.required' => 'The Your Availability Field is Required',
'commitments.required' => 'The Your Prior Commitments Field is Required',
'hear_about_us.required' => 'The How Did You Hear About Us Field is Required',
'comments.required' => 'The Comments Field is Required'
];
// dd($input);
$validator = Validator::make($input, $rules, $messages);
if ($validator->fails()) {
$ivInputs = [];
foreach($validator->invalid() as $key => $value){
$ivInputs[] = $key;
}
return json_encode(array("pass" => false, "message" => $validator->messages()->all(), 'ivInputs' => $ivInputs));
}
else {
Mail::send('emails.submitApplication', $input, function($message) use ($input) {
$message->from("noreply@test.com", "New Employment Application");
$message->to('test@test.com')->subject('New Employment Application');
});
return json_encode(array("pass" => true, "message" => "You Have a New Employment Application"));
}
}
<h4>You Have a New Application from {{$name}}</h4>
<hr>
<h3>General Contact Information</h3>
<hr>
<p>Name: {{$name}}</p>
<p>Email: {{$email}}</p>
<p>Phone Number: {{$phone}}</p>
{{-- <p>Comments: {{$comments}}</p> --}}
<hr>
<h3>Employment History</h3>
<hr>
<p>Employer 1 Start Date: {{$emp_1_start}}</p>
<p>Employer 1 End Date: {{$emp_1_end}}</p>
<p>Employer 1 Title: {{$emp_1_title}}</p>
<p>Employer 1 Salary: {{$emp_1_salary}}</p>
<p>Employer 1 Supervisor Name: {{$emp_1_sup_name}}</p>
<p>Employer 1 Supervisor Phone: {{$emp_1_sup_phone}}</p>
<p>Employer 1 Supervisor Duties: {{$emp_1_duties}}</p>
<hr>
<p>Employer 2 Start Date: {{$emp_2_start}}</p>
<p>Employer 2 End Date: {{$emp_2_end}}</p>
<p>Employer 2 Title: {{$emp_2_title}}</p>
<p>Employer 2 Salary: {{$emp_2_salary}}</p>
<p>Employer 2 Supervisor Name: {{$emp_2_sup_name}}</p>
<p>Employer 2 Supervisor Phone: {{$emp_2_sup_phone}}</p>
<p>Employer 2 Supervisor Duties: {{$emp_2_duties}}</p>
<hr>
<p>Employer 3 Start Date: {{$emp_3_start}}</p>
<p>Employer 3 End Date: {{$emp_3_end}}</p>
<p>Employer 3 Title: {{$emp_3_title}}</p>
<p>Employer 3 Salary: {{$emp_3_salary}}</p>
<p>Employer 3 Supervisor Name: {{$emp_3_sup_name}}</p>
<p>Employer 3 Supervisor Phone: {{$emp_3_sup_phone}}</p>
<p>Employer 3 Supervisor Duties: {{$emp_3_duties}}</p>
<hr>
<h3>References</h3>
<hr>
<p>Reference 1 Name: {{$ref_1_name}}</p>
<p>Reference 1 Phone Number: {{$ref_1_phone}}</p>
<p>Reference 1 Relationship: {{$ref_1_relationship}}</p>
<hr>
<p>Reference 2 Name: {{$ref_2_name}}</p>
<p>Reference 2 Phone Number: {{$ref_2_phone}}</p>
<p>Reference 2 Relationship: {{$ref_2_relationship}}</p>
<hr>
<p>Reference 3 Name: {{$ref_3_name}}</p>
<p>Reference 3 Phone Number: {{$ref_3_phone}}</p>
<p>Reference 3 Relationship: {{$ref_3_relationship}}</p>
<hr>
<h3>Other Information</h3>
<hr>
<p>Availability: {{$availability}}</p>
<p>Commitments: {{$commitments}}</p>
<p>How Did You Hear About Us?: {{$hear_about_us}}</p>
<p>Comments: {{$comments}}</p>
答案 0 :(得分:3)
只需将<p>Employer 1 Start Date: {{$input['emp_1_start']}}</p>
更改为<p>Employer 1 Start Date: {{$emp_1_start}}</p>
。