Hi!
I am using BuddyPress with “SuitePlugins – Advanced XProfile Fields for BuddyPress”, and I created some custom fields. On the registration page I want to check if ex. “idofcertificate” custom field data exist in the database. If exist then throw an error, to only one account to be created with this “idofcertificate”. There is any ideea how to do this?
Thank you very much!
Hi,
Welcome to BuddyDev and thank you for asking the question.You can do it on bp_signup_validate action. I am showing it with a example. You will need to check for duplicate on your own as I am not sure how are you storing or from which table you want to check for the data(Is it the profile data table?)
You will also need to know the field id to find the submitted content
/** * Validation error. */ function budydev_custom_validate_signup() { $field_id = 32;// please change with your field id. $field = isset( $_POST[ 'field_' . $field_id ] ) ? trim( $_POST[ 'field_' . $field_id ] ) : ''; // validate your field // from database // and if there is any error, // add the error to BuddyPress as buddypress()->signup->errors[ 'field_' . $field_id ] = "Your error message"; } add_action( 'bp_signup_validate', 'budydev_custom_validate_signup' );
Regards
BrajeshHi Leile,
I don’t see any function that does it. It will be faster and simpler to write a query. If you want, I can do that for you.
Thank you
BrajeshHi!
Thank you very much, I created the query, then the complete code:
function budydev_custom_validate_signup() { global $wpdb; $field_id = 13; $field = isset( $_POST[ 'field_' . $field_id ] ) ? trim( $_POST[ 'field_' . $field_id ] ) : ''; $qry = "SELECT value FROM wp_bp_xprofile_data WHERE value = " . $field; $result = $wpdb->get_results( $qry ); if(!empty($result)) { buddypress()->signup->errors[ 'field_' . $field_id ] = 'error message'; } }
Hi,
That will work.
May I suggest using the following$table = buddypress()->profile->table_name_data; $qry = $wpdb->prepare( "SELECT value FROM {$table} WHERE field_id = %d AND value = %s", $field_id, $field ); $result = $wpdb->get_var( $qry );
instead of
$qry = "SELECT value FROM wp_bp_xprofile_data WHERE value = " . $field; $result = $wpdb->get_results( $qry );
It will work even when the prefix for database is different than wp_ and sanitizing the query is important to avoid any issue. Also, It limits the search for the value ot specific field id.
Bets Regards
BrajeshYou are welcome. I am glad it is juseful.
Bet Regards
Brajesh
The topic ‘ [Resolved] xprofile verify if custom field data exist on registration’ is closed to new replies.