Restrict Content Pro
rcp_form_errors
Coming soon: Restrict Content Pro is becoming Kadence Memberships. You may see both names used while we update the product, documentation, and customer experience.
Note: This content is provided as a resource within our developer documentation. Because custom code requires highly specific implementation, we encourage you to work with a qualified developer if you need guidance. You can find our recommended consultants here: https://codeable.io/developers/restrict-content-pro
This happens just after the registration form is validated. It lets you show errors for custom fields you have added.
Parameters
$posted (array) – Array of all information sent with the form.
Restrict Content Pro also passes a $customer object as a second argument. The example below only uses $posted.
Example
This example adds a custom registration checkbox with rcp_after_register_form_fields and sets an error if the checkbox is not checked.
/**
* Add a checkbox to the registration form.
*
* @return void
*/
function ag_rcp_after_register_form_fields() {
?>
<p>
<input name="rcp_sample_required_field" id="rcp_sample_required_field" type="checkbox" checked="checked" />
<label for="rcp_sample_required_field"><?php esc_html_e( 'Your field label*', 'rcp' ); ?></label>
</p>
<?php
}
add_action( 'rcp_after_register_form_fields', 'ag_rcp_after_register_form_fields' );
/**
* Validate form submission and add an error if the 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' );