Skip Navigation

[Resolved] How can I input the “web” user field in a user registration form?

This thread is resolved. Here is a description of the problem and solution.

Problem:

I have a user registration form and I would like to collect, as an additional info, the Word Press user "Web" field.

Solution:

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:

https://toolset.com/forums/topic/how-can-i-input-the-web-user-field-in-a-user-registration-form/#post-1136671

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

https://codex.wordpress.org/Function_Reference/wp_update_user

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by alvaroM-5 6 years ago.

Assisted by: Luo Yang.

Author
Posts
#1136597

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

#1136629

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"

#1136642

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..

#1136671

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

#1136734

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

#1137357

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

#1137450

Luo your solution works perfect, everything set now 🙂

Thank you!