Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Well - I checked the form and I see that the field "wpcf-container-bags" is not available with the form. That is why its not displaying the error.
Is that field is missing from the form?
=> hidden link
Minesh,
To answer your question regarding the add-parcel form, no wpcf-container-bags is not missing from the form, and has been replaced in the validation function with the correct field which is wpcf-container-bags-left which is also not on the form. That field is stored under in the parent container and keeps track of the bags left in the container and needs to be compared to the bags being input in the form for validation.
I've tested again after making the changes as described above, and the form is still not validating. I've attached a screenshot of what is being input on the form, you can see that the parent container selected is CON001 which has 10 bags left. I attempt to add 15 bags to the parcel, and it goes through without error. The major issue from what I can tell is that I'm unable to reference the parent container because the below line of code isn't grabbing the parent id.
$parent_container = $_POST['@container-parcel.parent'];
If that line of code is not the issue, please let me know and let's move on to whatever else it could potentially be. This ticket has been open for 12 days and I'm not any closer to finding a solution. This obviously presents a very large issue for both myself and my client as I am unable to continue development on their project. I need to get this closed out in the next 24 hours. If that is not going to be possible due to your current utilization please pull in another individual from the support team to assist so we can get this hammered out.
Thanks,
Matt
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Could you please check now - I've adjusted the validation code as given under to your current theme's functions.php file:
function ylstracking_validate_parcel ($field_data, $form_data) {
list($fields,$errors)=$field_data;
//Check to ensure correct from is being used, 'add outbound parcel form is form 41 in dev'
if ( 41 == $form_data['id'] ) {
//get id of parent post
$parent_container = $_POST['@container-parcel_parent'];
//get value of bags-left field from parent post
$available_bags = get_post_meta($parent_container,'wpcf-container-bags-left', true);
//compare the value entered in the form to the value of available_bags
if ($_POST['wpcf-parcel-bags'] > $available_bags) {
$errors['wpcf-parcel-bags'] = 'The container you selected does not have enough bags';
}
}
return array($fields,$errors);
}
add_filter('cred_form_validate','ylstracking_validate_parcel',10,2);
The issue was the field names were not unique in your previous site and this site. I tested with the same parent CON001 and input 15 bags and I can see its throws errors successfully now. Could you please confirm.
Minesh, confirmed the validation appears to be working just fine now.
Thank you again for all your help sir, it is sincerely appreciated.
Matt
Minesh,
Sorry to reopen, but I wanted to see what you meant by "The field names are not unique". I tried to duplicate the code to validate the container-totes-left against entered parcel-totes in the same manner, but I'm running into the same issue. Is there a duplicate field in the DB? I can't find one via the admin pages.
Thanks,
Matt
I figured it out Minesh, it would help if I actually uploaded the functions file into the theme folder I am using ...