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

Slack Signup
Newsletter Optin
Help Desk

Change field to read only after form submission

Labels

This Discussion is public

Notifications

Hello all~

I am pretty new to WordPress and Formidable Forms.  My apologies ahead of time for my lack of knowledge or wrong wording in writing this request for help.

I have a form with an amount requested field that after submitting, I want it to change to read only so that anyone else trying to edit the form cannot touch that field.   I sort of made a psudo code below but I dont know how to fill it out correctly.  Any help would be appreciated!

add_action('frm_after_create_entry', 'change_field_readonly', 42, 2);

function change_field_readonly($entry_id, $form_id){

    if ( $form_id == 5 ) {

field_id,15 = ['readonly'] = false;

} }

Form entries can only be edited by the person submitting it, if you've given them permission and they are logged in, or by administrators. Who would have access to an entry after it's filled out?

Changing a field to read only, is a front-end function. In other words, it happens in the browser with CSS. It does not change the field to read only in the database. Anyone with authorized access to the database or WordPress administrator area can still change the data. You can't make a field read only in the database.

This means that frm_after_create_entry is the wrong hook. Since you already saved the information to the database, you can only make it read only as you retrieve the data to display it to edit it. You have to use frm_setup_edit_fields_vars https://formidableforms.com/knowledgebase/frm_setup_edit_fields_vars/

Thank you so much!  That was exactly what I needed.  You are amazing!

Hello vfontjr,

Thank you so much for your assistance in pointing me in the correct directly. So I found that it immediately sets the field to read only. I wanted the field to be changed to read only AFTER I submit the form not while I am filling out the form.

add_filter('frm_setup_edit_fields_vars', 'frm_set_read_only', 20, 3);
function frm_set_read_only($values, $field, $entry_id){
global $wpdb;
$results = $wpdb->get_results( 'SELECT * FROM formedit WHERE form_id = '.$form_id );
// If on front-end, make specific fields read-only
in_array( $field->id, array( 1558,554,555,556 ) )+
$values['read_only'] = 1;
}
return $values;
}

I am wondering if I could add into the if statement some sort of isset() check to check if that field is set before setting to read only?

Thank you in advance for any assistance.

Discussion closed.