Hi,
I have a user registration form and I would like to collect, as an additional info, the Word Press user "Web" field.
When I click "add field" when creating the User Registration Form I get the standard Word Press user fields (name, email, etc), but "Web" field is not in there.
How can I collect this "Web" field?
Also, I would like to validate that all fields in my user registration form are populated, if not display an error message - which is the quickest way to do this?
Thanks a lot.
Alvaro
Dear Alvaro,
I suggest you check these:
1) Edit the custom user field group, in section "Settings for the fields group", you can setup the user roles value.
2) Edit the Toolset user form, option "Role of the user", make sure it using a value in above user roles.
And I suggest you generate the user form content by clicking button "Auto-generate form content"
Hi Luo,
Sorry but I' not sure where those options are - could you attach screenshots of where to find them?
I'm a bit confused about you talking about "custom user field". The "Web" field is NOT a custom field, you can see it on every user created in Word Press.
Thanks..
Thanks for the details, I assume we are talking about the "Website" field in profile page.
you are right, there isn't built-in option for the "Website" field, as a workaround you can setup a generic field for user to input his website URL, and use custom codes to save it into database, for example,
1) Edit your user form for creating new users, add a generic URL field:
[cred_generic_field type='url' field='user_url']
{
"required":0,
"validate_format":0,
"default":""
}
[/cred_generic_field]
2) Add below codes into your theme file "functions.php":
add_action('cred_save_data', 'creation_client',10,2);
function creation_client($user_id, $form_data)
{
// if a specific form
if ($form_data['id']==1234)
{
$userData = array(
'ID' => $user_id,
'user_url' => $_POST['user_url'],
);
wp_update_user( $userData );
}
}
Please replace 1234 with your user form's ID, and test again
More help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://codex.wordpress.org/Function_Reference/wp_update_user
Hi Luo,
Works perfect! 🙂
Re my second question:
"Also, I would like to validate that all fields in my user registration form are populated, if not display an error message - which is the quickest way to do this?"
I can see that I can set required=true (1) for this generic field, which works ok.
BUT if I set this in my User Registration Form:
[cred_field field='first_name' post='user' value='' urlparam='' class='form-control' output='bootstrap' required='true']
Validation does NOT work i.e. the user form validation IGNORES the <<< required='true' >>> , you can leave the first name blank and it does not complain, why??
Thanks
There isn't such a built-in feature within shortcode [cred_field], see our document:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
The attribute "required" works only for parent post selector field:
required Optional. Select whether parent field is required. Defaults to false
In your case, you can try with some JS codes, add HTML 5 attribute "required" to those fields, for example:
(function( $ ) {
// javascript code here.
$('input[name="first_name"]').attr('required', 'required'); // radio and checkboxes
})(jQuery);
More help:
hidden link
Luo your solution works perfect, everything set now 🙂
Thank you!