I'm running into an issue with custom validation messages. Here's my code:
$input = array(
'email' => Input::get('email'));
$messages = array(
'email.required' => 'The darn email is required man!',
'email.exists' => 'That email address is already being used!',
'email.email' => 'Bad email, Bad.');
$rules = array(
'email' => 'required|exists:users,email|email');
My passback to the Laravel view is:
#foreach( $errors->all() as $message )
<li>{{ $message }}</li>
#endforeach
With this, I enter no email address and get:
"The darn email is required"
... Good!
Then I enter an email address that exists in the DB:
"That email address is already being used!"
... Good!
Then I enter an invalid email address like "noemail":
"That email address is already being used!"
"Bad email, Bad."
Why am I getting two messages when I should only be getting the one associated with the email.email custom attribute? (i.e., the "Bad email, Bad." message)?
Thanks!
Figured it out....
needed to be using the unique:table,column option, not exists.
Related
Trying to perfect an email form input, where the user can enter their email that is to be associated to their account. However ideally, the system would reject/accept the entered email once they have finished typing (not on form submission). I am using CodeIgniter, and still learning alot unfortunately.
My VIEW/form has the following input:-
<?=form_input(array(
'name' => 'pi_email',
'id' => 'pi_email',
'value' => isset($email)?$email:'',
'maxlength' => '50',
'required' => 'yes',
'size' => '50',
'placeholder' => 'johndoe#example.com',
'class' => 'lg-textbox'
));?>
On the controller/profile, I have the below as a test to try and catch these inputs and echo if taken or not, right now option 1 is always displayed as "email already taken", when they are not actually. I have seen the below form_validation online, however I do not generally understand the context in which it is to be used successfully
$this->form_validation->set_rules($new_email, 'Email', 'required|valid_email|is_unique[tbl_users.email]');
if($this->form_validation->run() == false){
echo "email already taken";
} else {
echo "Valid email!";
}
How could i implement real time check that will display on screen? I know how to use db model to run a query and return results, if = 0 valid, if > 0 then email taken? can this be implemented on the view or has to be done in the controller and then return user to the profile page and display an error message?
Any assistance, general pointing in the right direction would be great
So basically I have a simple form and one of the fields is an email.
My controller responsible for this form is the following(showing only the essentials)
$messages = array(
'rsvp_email.required' => 'A valid email is required.')
);
$rules = array(
'rsvp_email' => 'required|max:150|email',
);
$validator = Validator::make($request->all(), $rules,$messages);
Now there are 2 scenarios:
a) The email is not inserted and the above validation works with the custom message(This works OK)
b) The email is not in a valid format (myemail#email) and the resulted error message is The rsvp email must be a valid email address. which is not what I want to be displayed.
What additional rule should I include for a valid email?
Thank
IF you want to change this message go to the following path:
resources/lang/en/validation.php
and change value of email index.
I have a database table that tracks and email address and a client id. The rule is that and email can only belong to one client id. An example would be that I could add, email#domian.com and the client_id 20 but I would not be able to save that again, and this is where the form validation comes in,
I have the following validation rules in my controller,
$data = Input::all();
$client_id = Input::get('client_id');
$validation = Validator::make(
array('email' => Input::get('email')),
array('email' => 'required|email|unique:emails, email, NULL, client_id, $client_id')
);
if($validation->fails()) {
return Response::json($validation->messages(), 400);
} else {
}
Basically I am saying that the email should be a valid email and it should be unique against all the other emails adress that have the same client id.
However I get a PHP error back,
Undefined offset: 1
The POST that I am sending looks like this,
client_id: "16"
email: "simon#simonainley.info"
involved: 1
project_id: "64"
visible: true
I add validator to email element:
$usr_email->addValidator('Db_NoRecordExists', true, array('users', 'usr_email'));
And now have error message: A record matching 'admin#example' was found
I want change this error, but I want that will display inserted email
A email 'admin#example' already exist in database
I try , but email not disply ant html tags
addErrorMessage("**This email **strong text** address already exist.**");
Use %value% placeholder in the error message, it will be replaced with the actual value.
Example:
$usr_email->addValidator('Db_NoRecordExists', true, array(
'users',
'usr_email',
'messages' => array(
'recordFound' => 'A email %value% already exist in database'
)));
I want to create a Drupal user account without an email address. How can I create that? If I write a custom query which tables do I have to insert values in? Or does Drupal have a built-in function for that?
I have only user's first name, last name, password details. I want to create a user with only this information.
This will work, even email is required:
$newUser = array(
'name' => 'your username',
'pass' => 'any password', // note: do not md5 the password
'status' => 1,
);
user_save(null, $newUser);