Limiting Form submissions to once per day

By: James Bailey | Asked: 09/02/2023
ForumsCategory: Code HelpLimiting Form submissions to once per day
James Bailey asked 8 months ago
Hi  I'm trying to limit form entires to one per day, but the code i'm using is not working, this is the page that the form is on - - and this is the code i'm using:   // ONE ENTRY PER DAY function rehome_form_check($errors, $posted_field, $posted_value){ if($posted_field->id == 66){ //change 25 to the ID of the field to validate global$wpdb; $entry_id = (isset($_POST['id'])) ? $_POST['id'] : 0; $entries = $wpdb->get_col($wpdb->prepare("SELECT item_id FROM".$wpdb->prefix."frm_item_metas em LEFT JOIN ".$wpdb->prefix."frm_items e ON (em.item_id = WHERE e.created_at > %s AND em.meta_value=%s AND item_id != %d", date('Y-m-d H:i:s', strtotime('-24 hours')), $_POST['item_meta'][$posted_field->id], $entry_id)); //Midnight   if(count($entries) >= 1) { //change allowed count here $errors['field'.$posted_field->id] = 'That has been submitted today!'; } } return$errors; // var_dump($entries); } add_filter('frm_validate_field_entry', 'rehome_form_check', 8, 3);       Any help would be greatly appreciated  
1 Answers
Victor Font answered 8 months ago
Are you trying to restrict entries to one per user or one per form regardless of how many users?
James Bailey replied 8 months ago

Hi Victor

I want to restrict one submission per user in a 24 hour period.


Victor Font replied 8 months ago

Your code doesn’t take the user id into account. Users must be registered in WordPress and the user id needs to be captured on the form. Then you can use the combination of user id and create date as your filter. If your users aren't registered as WordPress users, you have to decide on a combination of data values you're capturing on the form to construct a unique electronic fingerprint.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community