php to validate member before to send result

Labels

This Discussion is public

Notifications

Hi,

I need to validate the customer membership status in a specific hidden field. Thus I think that a php module checking 3 items in the wpdb would allow me using a function [IF] (form parameters), either to send directly the created Pro2Pdf file if it is a [MEMBER] member, or to redirect towards a specific page if it is not a member [NOT MEMBER].

I tried to write a short code but it does not work 🙁

Any help will be appreciate

Philippe

My 'not working code' below :

function form_validate_members( $errors, $values ) {
if ( $values['form_id'] == 38 && !empty( $_POST['item_meta'][1234] ) ) {// 1234 is the Member registered number field, just check that it's not empty
global $wpdb;

$fnh = $wpdb->get_var( $wpdb->prepare( "SELECT item_id FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND meta_value=%s",
1258, $_POST['item_meta'][1234] ) );

$siret = $wpdb->get_var( $wpdb->prepare( "SELECT item_id FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND meta_value=%s",
1257, preg_replace( '/D/', '', $_POST['item_meta'][5678] ) ) );// Remove dashes, 5678 is the SIRET (Company Identification number field)

// Prepare the "item_id IN ({$ids})" phrase below
$ids = $fnh ? $fnh : "";
$ids .= ($fnh && $siret) ? "," : "";
$ids .= $siret ? $siret : "";

$name = '%' . $wpdb->esc_like( $_POST['item_meta'][9012] ) . '%';// 9012 is the NAME number field

$name = $wpdb->get_var( $wpdb->prepare( "SELECT item_id FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND meta_value LIKE %s AND item_id IN ({$ids})",
1264, $name ) );// Checks to make sure the item_id matches one of the first 2, because people can have the same last name!

if ( $fnh && $siret && $name ) {// found all 3

if ( $fnh === $siret && $fnh === $name ) {// all 3 match

$result = "MEMBER ( # $fnh > FNH-MEMBERS)";
}
else {// they don't match
$result = "Toutes les données trouvées mais sur des enregistrements différents ! Vérifier les saisies de la base FNH-MEMBERS $fnh $siret and $name";
}
}
else {// didn't find all 3
$result = $fnh ? "No. FNH valide $fnh" : "No. FNH inconnu";
$result .= $siret ? ", No. SIRET valide $siret" : ", No. SIRET inconnu";
$result .= $name ? ", NOM valide $name" : ", NOM inconnu";
}

$_POST['item_meta'][4050] = $result;// Post result to field 4050, a hidden field at the top of form 38
}
return $errors;
}

Reply to this Discussion