Laravel - Change error message for Authenticates user - laravel

I changed login condition as per my requirement in AuthenticatesUsers
protected function credentials(Request $request)
{
return array_merge($request->only($this->username(), 'password'), ['is_approved' => 1]);
}
But for Not Approved error message is These credentials do not match our records.
How to change this message?

did you mean validations?? you can change it using the novalidation. just insert that at the end of the form. if it does not work, you can use a js.
here's a sample js:
var $ = jQuery;
$(document).ready(function($) {
$("form[name='Cust_Form']").validate({
errorElement: 'div',
rules: {
postal_code: {
number: true,
minlength: 4,
maxlength: 4,
required: true
},
email: {
email: true
},
unit: {
number: true
},
building: {
number: true
},
contact_2: {
number: true,
minlength: 11,
maxlength: 11
},
contact_1: {
number: true,
minlength: 11,
maxlength: 11
}
},
// Specify validation error messages
messages: {
postal_code: {
minlength: "Your postal code must be at least 4 characters long",
number: "Please enter a valid postal code",
maxlength: "Your postal code must be at least 4 characters long",
required: "Required field"
},
email: {
email: "Please enter a valid email address"
},
unit: {
number: "Please enter a valid unit number"
},
building: {
number: "Please enter a valid building/house number"
},
contact_1: {
minlength: "Your contact number must be at least 11 characters long",
number: "Please enter a valid contact number",
maxlength: "Your contact number must be at least 11 characters long"
},
contact_2: {
minlength: "Your contact number must be at least 11 characters long",
number: "Please enter a valid fax/phone number",
maxlength: "Your contact number must be at least 11 characters long"
},
},
// Make sure the form is submitted to the destination defined
// in the "action" attribute of the form when valid
submitHandler: function(form) {
form.submit();
}
});
});

Related

Lightbox Not Working with jQuery

I have a problem with lightbox after loading the following script in my page:
jQuery.validator.addMethod('answercheck', function (value, element) {
return this.optional(element) || /^\b5\b$/.test(value);
}, "please type the correct answer (this is anti-spam)");
// validate contact form
$(function() {
$('#contact').validate({
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
answer: {
required: true,
answercheck: true
}
},
messages: {
name: {
required: "please enter your name",
minlength: "your name must consist of at least 2 characters"
},
email: {
required: "please enter your email address"
},
answer: {
required: "sorry, wrong answer! (this is anti-spam)"
}
},
submitHandler: function(form) {
$(form).ajaxSubmit({
type:"POST",
data: $(form).serialize(),
url:"process.php",
success: function() {
$('#contact :input').attr('disabled', 'disabled');
$('#contact').fadeTo( "slow", 0.15, function() {
$(this).find(':input').attr('disabled', 'disabled');
$(this).find('label').css('cursor','default');
$('#success').fadeIn();
});
},
error: function() {
$('#contact').fadeTo( "slow", 0.15, function() {
$('#error').fadeIn();
});
}
});
}
});
});
I have read about .live() and read this page http://api.jquery.com/live/ but I am a newbie and have trouble implementing it in my script. Any help please?
thank you

Kendo UI Inline Grid

I am having an issue with validation on certain fields. I want to only validate on a couple of fields, and the other fields should not validate. In my Email field, I am firing a function to check proper formatting, but the other fields are simply set to validate. Any help would be greatly appreciated.
model: {
id: "UserID",
fields: {
UserID: { editable: false },
CompanyID: { editable: false },
FirstName: { type: "string", validation: { required: { message: "Name is required"} } },
LastName: { type: "string", validation: { required: { message: "Name is required" } } },
Email: {
type: "string",
validation: {
required: { message: "Email is required." },
validateEmailFormat: function(input) {
if (input.attr("data-bind") == "value:Email") {
input.attr("data-validateEmailFormat-msg", "Email format invalid.");
return checkEmail(input.val());
}
return true;
}
}
},
PhoneNumber: { type: "string" },
Extension: { type: "string" }
}
}
With this code, all fields are being validated when trying to save/update. I don't want Extension or PhoneNumber to validate.
In your update/Save action, You can remove your fields from the ModelState which don't want to valid, like :
ModelState.Remove("PhoneNumber");
ModelState.Remove("Extension");

When I add remote to Jquery Validate form submits when invalid

When I add remote to the jquery validate my form submits even if there are errors, when I remove remote it works properly and you can't submit the form and unless you have filled in all fields? Any ideas? code is below
<script>
$(document).ready(function () {
$("#SignUp").validate({
onsubmit: true,
onkeyup: function(element) { $(element).valid(); },
rules: {
email: {
required: true,
email: true
},
password: {
required: true,
password: true
},
confirm_password: {
equalTo: "#password",
required: true
},
company: {
nls:true,
required: true
},
telephone: {
required: true,
phoneUK: true
},
email2: {
email: true
},
website: {
url: true
},
address1: {
nls:true
},
address2: {
nls:true
},
town: {
nls:true
},
postcode: {
postcodeUK:true
},
country: {
selectcountry:true
},
terms:{
required:true
},
answer:{
remote: "Captcha/check-captcha.php",
type: "POST",
data: {
captcha: function() {
return $("#answer").val();
}
}
}
},
messages:{
email:
{
required: "Please Enter an Email Address"
},
password:
{
required: "Please Enter a Password"
},
confirm_password:
{
required: "Please Confirm Your Password"
},
company:
{
required: "Please Enter Your Company/Climbing Gym Name"
},
telephone:
{
required: "Please Enter a Telephone Number"
},
terms:
{
required: "Please Agree Our Terms and Conditions"
},
answer:{
remote: "You Have Entered The Captcha Correctly When This Message Disappears"
}
}
});
$.validator.addMethod("password", function (value, element) {
return this.optional(element) || /^[A-Za-z0-9!##$%^&*()_]{6,16}$/i.test(value);
}, "Passwords are 6-16 characters");
$.validator.addMethod("nls", function(value, element)
{
return this.optional(element) || /^[a-zA-Z0-9\s.\-_']+$/i.test(value);
}, "Please Only Enter Alpha Numeric Characters and Spaces");
jQuery.validator.addMethod('selectcountry', function (value) {
return (value != 'Nothing');
}, "Please Select a Country");
$.validator.addMethod("url", function(value, element)
{
return this.optional(element) || /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/i.test(value);
}, "Please Enter A Valid Website URL");
});
</script>
PHP is below:
<?php
session_start();
if(strtolower($_REQUEST['answer']) == $_SESSION['captcha']){
echo 'true';die;
}else{
echo 'false';die;
}
?>
The validation still works onkeyup etc with and without remote but just not on submit?
The remote rule syntax is slightly off in your case
answer: {
required: true,
remote: {
url: "Captcha/check-captcha.php",
type: "POST",
data: {
captcha: function () {
return $("#answer").val();
}
}
}
}

jQuery Validate - digits of min length of 10 or 13?

How do I create a custom validation rule for the jquery validate plugin that checks against the user's input as either 10 or 13 digits? Thanks much for the help.
Very simple sample of validation
$("#FormToValidatePhoto").validate({
rules: {
Title: { minlength: 10, maxlength: 13 }
},
messages: {
Title: { minlength: "Min is 10", maxlength: "Max is 13" }}
});

Jquery email validation of email and one specific message

I have a jquery syntax as below
Email: {
required: true,
email: true,
remote: {
url: "emails.php",
type: "post",
},
which validate a field as below;
<td class="field" style="width: 246px">
<input id="Email" name="Email" type="text" value="<?php echo $email; ?>" style="width: 246px">
</td>
<td class="status"></td>
which displays a success/error message in <td class="status">
It validate the data when a valid email ID is entered.
The ajax callback is a simple true/false data.
What i want is, it should also validate when a specific message "NA" is entered in the field. Is this possible??
Here is the complete javascript;
<script id="demo" type="text/javascript">
$.noConflict();
jQuery(document).ready(function($) {
var validator = $("#signupform").validate({
rules: {
ID: "required",
Name: {
required: true,
minlength: 5,
},
Address: "required",
Dept: "required",
Phone: "required",
College: "required",
LDate: "required",
EDate: "required",
Year: "required",
Privilage: "required",
username: {
required: true,
minlength: 5,
},
Email: {
required: true,
email: true,
remote: {
url: "emails.php",
type: "post",
},
},
LibID: {
required: true,
},
},
messages: {
ID: "Enter ID",
Name: "Enter Name",
Address: "Enter Address",
Phone: "Enter Phone Number",
College: "Specify College",
LDate: "Enter Licenseing Date",
EDate: "Specify License Expiry Date",
Year: "Specify Year",
Dept: "Specify Department",
Privilage: "Specify Privilage",
username: {
required: "Enter a username",
minlength: jQuery.format("Enter at least {0} characters"),
remote: jQuery.format("username not available")
},
Email: {
required: "Enter a valid email address",
minlength: "Enter a valid email address",
remote: jQuery.format("already registered"),
},
LibID: {
required: "Enter a Library ID",
minlength: "Enter a Library ID",
remote: jQuery.format("ID is already in use"),
},
},
errorPlacement: function(error, element) {
error.appendTo( element.parent().next() );
},
success: function(label) {
label.html("OK").addClass("checked");
}
});
$('.username').alphanumeric({nocaps:true}).alphanumeric({ichars:'._'});
});
</script>
Thanks in advance :)
blasteralfred.
I assume you are using the jquery.validation plugin.
If thats the case you can use depends with email rule:
Email: {
required: true,
email: {
depends: function(element){
return element.value != "NA";
}
},
remote: {
url: "emails.php",
type: "post",
},
}

Resources