Form validation on Laravel 5

I seem to have a problem with this function which is used in a contact form. This form was made by a developper I get this message displaying in a random way : “An Error Occured..” when I click Submit button in my form. Most of time I get this error message but on local I yesterday got it not displayed and bassed to the next step and validated the form. Problem is I was not able to reproduce it.

I found the controler use a PostIndex function as follow

    public function postIndex($origin = '')
{
$input = Input::only('title','name','country_id','company','company_website','phone_number','email','message');
$input['origin'] = $origin;
$input['ip'] = getIP();
// Create a new validator instance from our validation rules
$validator = Validator::make($input, ContactUs::$rules );

// If validation fails, we'll exit the operation now.
if ($validator->fails())
return Redirect::route('contact-us')->withErrors($validator);
try {
$contact = ContactUs::create($input);
} catch (Exception $e) {
return Redirect::back()->withInput()->with('error', 'An Error Occured..');
}
return Redirect::route('contact-us.show',$contact->token)->with('success', 'We have received your message.');

}

I suppose there is an issue with the validator relatd to rules which are defined as follow

public static $rules = array(
'title' => 'required',
'name' => 'required',
'email' => 'required|email',
'country_id' => 'required|exists:countries,id',
'company' => 'required',
'company_website' => 'required',
'phone_number' => 'required',
'message' => 'required',
);

This is the form field:

<div class="form-group ">
<label class="col-lg-3 " for="title">Title: <sup>*</sup></label>
<div class="col-lg-8">



</div>
</div>
<div class="form-group ">
<label class="col-lg-3" for="name">Name: <sup>*</sup></label>
<div class="col-lg-8">
<input type="text" class="form-control required "
name="name" id="name" value="" required>

</div>
</div>
<div class="form-group ">
<label class="col-lg-3" for="email">Email: <sup>*</sup></label>
<div class="col-lg-8">
<input type="email" class="form-control required "
name="email" id="email" value="" required>

</div>
</div>
<div class="form-group ">
<label class="col-lg-3" for="country_id">Country: <sup>*</sup></label>
<div class="col-lg-8">


</div>
</div>
<div class="form-group ">
<label class="col-lg-3" for="company">Company Name: <sup>*</sup></label>
<div class="col-lg-8">
<input type="text" class="form-control required " required name="company" id="company" value="">

</div>
</div>
<div class="form-group ">
<label class="col-lg-3" for="company_website">Company Website: <sup>*</sup></label>
<div class="col-lg-8">
<input type="url" class="form-control required " required name="company_website" id="company_website" value="">

</div>
</div>
<div class="form-group ">
<label class="col-lg-3" for="phone_number">Phone Number: <sup>*</sup></label>
<div class="col-lg-8">
<input type="text" class="form-control hidden " name="phone_number" id="phone_number" placeholder="in internal format e.g : +185523232422" value="">
<input type="tel" id="phone" class="form-control">
<div id="valid-msg" class="hide text-aqc-green val_msg">✓ Valid</div>
<div id="error-msg" class="hide text-aqc-red val_msg">Invalid number</div>

</div>
</div>
<div class="form-group ">
<label class="col-lg-3" for="message">Your Message: <sup>*</sup></label>
<div class="col-lg-8">
<textarea name="message" id="message" class="form-control" style="min-height:150px;max-height:200px;" placeholder="Place Your Message Here" required></textarea>
</div>
</div>

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/3kAuWVD
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.