Draft Saving (Custom)

By: Rob LeVine | Asked: 03/24/2023
ForumsCategory: General questionsDraft Saving (Custom)
Rob LeVineRob LeVine asked 1 year ago

Formidable only supports one draft per user and I needed to have an unlimited number of drafts per user. Exacerbating the problem for me was that I had a bazillion required fields, meaning I couldn't save it without either giving each one a value or defaulting all of them to something. That wasn't going to work. Here's how I solved it:

1. Added a hidden field to your form and give it a key "is_draft" (or whatever you want, as long as you propagate it through the next steps).

2. Form Settings->Form Permissions make sure "Allow logged-in users to save drafts" is unchecked.

3. Form Settings->Customize HTML change the following:
https://pastebin.com/AVgX6hnN

4. Add the following jQuery code to your page (replacing my_saveDraft and my_save with the same values in the previous step and field_is_draft with whatever you used in step 1.
https://pastebin.com/3FSeKfPe

5. To silence the required field errors, use frm_validate_entry as follows:
https://pastebin.com/NhA5zwcX

Mark Koncurat replied 1 month ago

This is great! The only issue is that it saves as completed instead of as a draft. Anyway around it?

Mark Koncurat replied 1 month ago

Thank you for your response. I'm trying the following code, but it's not quite right:

add_action('frm_after_create_entry', 'update_draft_status', 20, 2);
function update_draft_status($entry_id, $form_id){
if($form_id == 2){
global $wpdb;
if ($_POST['item_meta'][102] == "Yes") {
$wpdb->update( $wpdb->prefix .'frm_items', array('is_draft'=>1));
}else{
$wpdb->update( $wpdb->prefix .'frm_items', array('is_draft'=>0));
}
}
}

Rob LeVineRob LeVine replied 1 month ago

Well, you have to be more clear than "not quite right". What is it doing or not doing? One thing that's clear to me is that without a where clause (param 3 of wpdb->update) it's going to update all of your entries for every form.

Mark Koncurat replied 1 month ago

Thanks! That would do it.

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
crossarrow-right