rcp_after_register_form_fields

Note: This is part of the developer docs and is considered custom code.
Unfortunately, we cannot provide support for custom code at this time as we do not have the additional resources that would be necessary to provide support for custom code.

If you need assistance with this, please reach out to our list of consultants for further assistance:
https://codeable.io/developers/restrict-content-pro/

Used to add extra form fields to the end of the registration form. Fields added here are displayed directly above the gateway selection.

Use rcp_form_errors to validate form fields.

Example:

This example shows adding a custom registration field (checkbox) and validation that sets an error if the checkbox isn't checked (using rcp_form_errors).

/**
 * Add checkbox to registration form.
 * 
 * @return void
 */
function ag_rcp_after_register_form_fields() {
	ob_start(); ?>
		<p>
			<input name="rcp_sample_required_field" id="rcp_sample_required_field" type="checkbox" checked="checked"/>
			<label for="rcp_sample_required_field">Your field label*</label>
		</p>
	<?php
	echo ob_get_clean();
}

add_action( 'rcp_after_register_form_fields', 'ag_rcp_after_register_form_fields' );

/**
 * Validate form submission and add an error if checkbox isn't checked.
 * 
 * @param array $posted Array of information sent to the form.
 * 
 * @return void
 */
function ag_rcp_form_errors( $posted ) {
	if( ! isset( $posted['rcp_sample_required_field'] ) ) {
		rcp_errors()->add( 'sample_field_required', __( 'You must check this field', 'rcp' ), 'register'  );
	}
}

add_action( 'rcp_form_errors', 'ag_rcp_form_errors' );
Have more questions? Submit a request
Powered by Zendesk