The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
frm_validate_field_entry unexpected results
Hi all,
First let me state that I am not a PHP programmer (I haven't coded since the early 80's (IBM 360 Assembler!), so this may be a simple "one D ten T" error.
By looking at the documentation and examples in the documentation and on the forum I was able to grok approximately what I need to do. I can get things to work individually, but when I activate all the options I get an wrong result and I do not know how to fix it,
The form is an event registration form. There are three fields accessed in the code - an admission type radio button [101]; and admin-only paid/notpaid dropdown [100] and user-type fields [179] (user-type is picked up from another form - user-account).
Here's the code:
add_filter('frm_validate_field_entry', 'hawk_gamemaster', 10, 3);
function hawk_gamemaster($errors, $posted_field, $posted_value ){
if( $posted_field->id == 179){
if( $_POST['item_meta'][$posted_field->id] = "HAWK" ){
$_POST['item_meta'][101] = "$10 - Gamemaster*";
}
}
return $errors;
}
add_filter('frm_validate_field_entry', 'hawk_paid', 10, 3);
function hawk_paid($errors, $posted_field, $posted_value){
if( $posted_field->id == 179 ){
if( $_POST['item_meta'][$posted_field->id] = "HAWK" ){
$_POST['item_meta'][100] = "Paid";
}
}
return $errors;
}
add_filter('frm_validate_field_entry', 'vendor_gamemaster', 10, 3);
function vendor_gamemaster($errors, $posted_field, $posted_value){
if( $posted_field->id == 179 ){
if( $_POST['item_meta'][$posted_field->id] = "Vendor" ){
$_POST['item_meta'][101] = "$10 - Gamemaster*";
}
}
return $errors;
}
add_filter('frm_validate_field_entry', 'vendor_paid', 10, 3);
function vendor_paid($errors, $posted_field, $posted_value){
if( $posted_field->id == 179 ){
if( $_POST['item_meta'][$posted_field->id] = "Vendor" ){
$_POST['item_meta'][100] = "Paid";
}
}
return $errors;
}
add_filter('frm_validate_field_entry', 'child_paid', 10, 3);
function child_paid( $errors, $posted_field, $posted_value){
if( $posted_field->id == 101 ){
if( $_POST['item_meta'][$posted_field->id] = "$0 - Child (age12 and under)*" ){
$_POST['item_meta'][100] = "Paid";
}
}
return $errors;
}
If the value of the user-type field [179] is HAWK or Vendor, then field 100 should be set to Paid and 100 should be set to "$10 - Gamemaster*", so that HAWK and Vendor can access other functions in the system currently controlled by being Paid up as a "$10 - Gamemaster*".
If the value of the admission type [101] is "$0 - Child (age12 and under)*", then field 100 should be set to Paid.
If I only have HAWK, or Vendor, or Child logic active, the code seems to work OK. With all the logic active, I get one result regardless of the radio selection or the user-type: [100] is set to Paid; [101] is set to "$10 - Gamemaster*"; and [179] is set to Vendor, even when the user account field it is originally populated from is blank or HAWK.
What am I doing wrong?
Thanks
John H.
November 1, 2017 at 7:23 am
Instead of using multiple functions, write the code as you stated it in the post all in one function. I've refactored the code for you. Obviously, I can't test it, but at this point, you can figure out the rest:
add_filter('frm_validate_field_entry', 'hawk_gamemaster', 10, 3);
function hawk_gamemaster($errors, $posted_field, $posted_value ){
if( $posted_field->id == 179){
$value = $_POST['item_meta'][$posted_field->id];
if( $value == "HAWK" || $value == "Vendor" ){
$_POST['item_meta'][100] = "Paid";
$_POST['item_meta'][101] = "$10 - Gamemaster*";
}
}
if( $posted_field->id == 101 ){
if( $_POST['item_meta'][$posted_field->id] = "$0 - Child (age12 and under)*" ){
$_POST['item_meta'][100] = "Paid";
}
}
return $errors;
}
November 1, 2017 at 8:20 am
Victor,
Thanks for your response. I have to say that a number of your responses in other threads were helpful in getting me this far!
Below is my code now (with a few label changes from what you posted).
All the standard attendee pay options work fine (they didn't before!); and the HAWK and Vendor special attendee types work fine.
For the Child admission type the Registered & Paid [100] is not updated from NotPaid (default value) to Paid.
This has been my problem for two days. I keep changing things around, but always have 1 or 2 scenarios (different ones) where I'm not getting the required result.
Any insight you can give would be greatly appreciated.
Thanks
John H.
add_filter('frm_validate_field_entry', 'special_attendees', 10, 3);
function special_attendees($errors, $posted_field, $posted_value ){
if( $posted_field->id == 179){
$value1 = $_POST['item_meta'][$posted_field->id];
if( $value1 == "HAWK" || $value1 == "Vendor"){
$_POST['item_meta'][100] = "Paid";
$_POST['item_meta'][101] = "$10 - Gamemaster*";
}
}
if( $posted_field->id == 101 ){
$value2 = $_POST['item_meta'][$posted_field->id];
if( $value2 == "$0 - Child (age12 and under)*" ){
$_POST['item_meta'][100] = "Paid";
}
}
return $errors;
}
November 1, 2017 at 10:16 am
The only thing I can suggest at this point is to make certain that value2 is an exact match to what you expect the value to be ($0 - Child (age12 and under)*). If there's an extra space, the if statement wont work. To test this, add var_dump( $value2 ); after you assign the value to $value2 to view the actual value.
Discussion closed.