A Cozmoslabs Product
Documentation / Developer Knowledge Base / Make Last Name and First Name fields required

Make Last Name and First Name fields required

By default, the First and Last Name fields from the form are not required. In order to make them required, you need to add the following snippet of custom code to your website:

add_filter( 'pms_register_form_label_first_name', 'pmsc_first_name_field_label');
function pmsc_first_name_field_label( $attributes ){
	return __( 'First Name *', 'paid-member-subscriptions' );
}

add_filter( 'pms_register_form_label_last_name', 'pmsc_last_name_field_label');
function pmsc_last_name_field_label( $attributes ){
	return __( 'Last Name *', 'paid-member-subscriptions' );
}

add_action( 'pms_register_form_validation', 'pmsc_first_last_validation' );
function pmsc_first_last_validation(){
	if( empty( $_POST['first_name'] ) )
		pms_errors()->add( 'first_name', __( 'This field is required.', 'paid-member-subscriptions' ) );

	if( empty( $_POST['last_name'] ) )
		pms_errors()->add( 'last_name', __( 'This field is required.', 'paid-member-subscriptions' ) );
}

You can download a small plugin containing this code from here. After downloading, you just need to install and activate it on your website.
The code can also be added inside the `functions.php` file from your child theme.

If you need help with any of this or have questions, don’t hesitate to contact our customer support.

Paid Member Subscriptions Pro

Accept (recurring) payments, create subscription plans and restrict content on your website. Easily setup a WordPress membership site using Paid Member Subscriptions.

Get Paid Member Subscriptions

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket