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
Allready exists
Hi
I have found the code below that checks if a date has allready been used. This works fine, but I need it to work for different users.
I a user login and select a date, then this date is user for that user, but another user may choose the same date once. Can someone help me with that?
Here is the code without the user tvist.
add_filter('frm_validate_field_entry', 'my_custom_validation', 10, 3);
function my_custom_validation($errors, $posted_field, $posted_value){
if($posted_field->id == 125 and !is_admin()){ //change 125 to the ID of the date field
$frmpro_settings = FrmProAppHelper::get_settings();
$selected_date = FrmProAppHelper::convert_date($posted_value, $frmpro_settings->date_format, 'Y-m-d');
//get all the entries for that date
$entries_for_date = FrmEntryMeta::get_entry_metas_for_field(125, '', '', array('value'=> $selected_date));
//change 125 to the ID of the date field
if(count($entries_for_date) >= 3) //change allowed count here
$errors['field'. $posted_field->id] = 'That date is full!';
}
return $errors;
}
Kind regards Gert
September 24, 2018 at 6:01 am
To check metadata for a single user, you would have to create a custom SQL query. Formidable uses 2 tables to store submitted form entries, wp_frm_items and wp_frm_item_metas. The used dates are stored in the wp_frm_item_metas table and the entry's header record is stored in wp_frm_items. The entry header holds the user ID of the person that submitted the form. The meta table links back to the entry header, but has no direct link to the user ID. It can get a little more complex if you are using a repeatable field for the date entry.
This means you have to create a relational SQL query to link both tables together. You have to work out the SQL in PHPMyAdmin first then convert that to a format that will work in WordPress with the global $wpdb object.
If you want to do this in real time, you have to use Ajax to invoke the call, otherwise the frm_validate_field_entry is fine.
Discussion closed.