Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Gravity form registration field validation error message hook WordPress

Hello,

I need some field error validation hook help.

I have a registration form. Very basic, consists of name, username and email.

The email form field is being used for both username and email registration addon fields. [[LINK href="http://i.imgur.com/UcuEIWq.png"]]Please see this screenshot[[/LINK]].

I am using the Enable Email Confirmation option in the email form field.

So now I have around 3 validation messages...

<strong>Please enter a valid email address.
Your emails do not match.
This email address is already registered </strong>


Which is painful because I only want to overide the <strong>This email address is already registered</strong> validation message with something like this...

<strong>You are already registered on the site using [email protected].
Please click here to login. If you have forgotten your password, you can create a new one here.</strong>

[[LINK href="http://www.gravityhelp.com/documentation/page/Gform_field_validation"]]This is the only field validation hook I can find but I'm stumped where to begin.[[/LINK]]

If I change the validation message in the form editor, it does noting.


My email field id is #3 and my form id is #3.

I am also using the latest gravity forms but with the version 1.4 for the registration add-on. This is because registration add-on 1.5 does not let you validate email address as the username. You get prompted with this validation message... <strong>Only lowercase letters (a-z) and numbers are allowed.</strong>

I have packaged/zipped up the versions of the plugins I am using [[LINK href="http://public.motocomdigital.co.uk/temp/plugins.zip"]]here[[/LINK]]


If anyone can help me out that would be awesome. Please let me know if it is possible and I can add some more money to the pot. But i'm dubious to wether or not it can be done? Ideally I want it to be done in php.


Thanks in advance
Josh

Answers (1)

2013-04-09

Kyle answers:

Hey, you are going to want to use gform_user_registration_validation hook, give me a second and I'll put something together


Kyle comments:

Here is my shot at the code, definitely a tricky one, let me know how this goes (untested because I'm running 1.5 on my sites)

add_filter('gform_user_registration_validation', 'new_validate_duplicate_email', 10, 2);
function new_validate_duplicate_email($form, $config) {

if($form['id'] != 3)
return $form;


$email_field_id = rgars($config, 'meta/email');
foreach($form['fields'] as &$field) {
if($field['id'] == $email_field_id && $field['validation_message'] == 'This email address is already registered')
$field['failed_validation'] = false;
add_filter("gform_field_validation_3_3", "new_email_validation_message", 10, 4);
}

return $form;
}

function new_email_validation_message($result, $value, $form, $field){

$user = wp_get_current_user();

$result["is_valid"] = false;
$result["message"] = "You are already registered on the site using "'.$user->user_email.'". Please click here to login. If you have forgotten your password, you can create a new one here.";

return $result;
}




Josh Cranwell comments:

Hi Kyle thanks for you answer.

I think it slightly not working for me, this is the function I am using.


add_filter('gform_user_registration_validation', 'new_validate_duplicate_email', 10, 2);
function new_validate_duplicate_email($form, $config) {
if($form['id'] != 3)
return $form;
$email_field_id = rgars($config, 'meta/email');
foreach($form['fields'] as &$field) {
if($field['id'] == $email_field_id && $field['validation_message'] == 'This email address is already registered')
$field['failed_validation'] = false;
add_filter("gform_field_validation_3_3", "new_email_validation_message", 10, 4);
}
return $form;
}
function new_email_validation_message($result, $value, $form, $field) {
$user = wp_get_current_user();
$result["is_valid"] = false;
$result["message"] = "You are already registered on the site using ".$user->user_email." Please click here to login. If you have forgotten your password, you can create a new one here.";
return $result;
}


The code is valid but it does not seem to return any validation message now on my email field.

Also I'm not sure if $user = wp_get_current_user(); will work because the person registering is not logged in yet. So there will be not user info to get. How about using the value variable?

I tired this but still no message was being returned...


/* GRAVITY HOOKS */
add_filter('gform_user_registration_validation', 'new_validate_duplicate_email', 10, 2);
function new_validate_duplicate_email($form, $config) {
if($form['id'] != 3)
return $form;
$email_field_id = rgars($config, 'meta/email');
foreach($form['fields'] as &$field) {
if($field['id'] == $email_field_id && $field['validation_message'] == 'This email address is already registered')
$field['failed_validation'] = false;
add_filter("gform_field_validation_3_3", "new_email_validation_message", 10, 4);
}
return $form;
}
function new_email_validation_message($result, $value, $form, $field) {
$result["is_valid"] = false;
$result["message"] = "You are already registered on the site using ".$value." Please click here to login. If you have forgotten your password, you can create a new one here.";
return $result;
}



Can you help?

Thanks



Kyle comments:

Try taking out the failed_validation line above add_filter and replace . I agree about the email, my mistake. I'll be able to give a better assistance in a few hours.


Josh Cranwell comments:

Ok thank you. I tried it no joy. I also removed the amplisand infront of... foreach($form['fields'] as $field) {


add_filter('gform_user_registration_validation', 'new_validate_duplicate_email', 10, 2);
function new_validate_duplicate_email($form, $config) {
if($form['id'] != 3)
return $form;
$email_field_id = rgars($config, 'meta/email');
foreach($form['fields'] as $field) {
if($field['id'] == $email_field_id && $field['validation_message'] == 'This email address is already registered')
$field['failed_validation'] = false;
add_filter("gform_field_validation_3_3", "new_email_validation_message", 10, 4);
}
return $form;
}
function new_email_validation_message($result, $value, $form, $field) {
$user = wp_get_current_user();
$result["is_valid"] = false;
$result["message"] = 'You are already registered on the site using '.$user->user_email.' <a href="'.wp_login_url(home_url()).'" title="Login">Please click here to login</a>. If you have forgotten your password, please <a href="'.wp_lostpassword_url().'" title="Create password">click here</a> to create a new one.';
return $result;
}


Josh Cranwell comments:

I need this pretty urgent so I figured it out with jQuery for a comprimise.

Guess it works fine but if you can manage to get your php version to work but if not I will still pay you the $10.


$(document).bind('gform_post_render', function(event, form_id){

if(form_id == 3) {

emailValue = $('#gform_3 #input_3_3').attr('value');

$("#gform_3 div.gfield_description.validation_message:contains('This email address is already registered')").html('You are already registered on the site using '+emailValue+', please <a href="<?php echo wp_login_url(home_url()); ?>&username='+emailValue+'" title="Login">click here</a> to login.<br/>If you have forgotten your password, please <a href="<?php echo wp_lostpassword_url() ?>&username='+emailValue+'" title="Create password">click here</a> to create a new one.');

}

});


Kyle comments:

May as well keep that then. The code above should get you started with a php solution. If you decide to go with a php solution you can pm me or raise the pot a bit.