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

form fields after submission/update to read only && only some users can edit once

Labels

This Discussion is public

Notifications

Hello!  I am a bit new to this and Formidable Forms has been kicking my butt!

 

I have a few things I need done.

  1.  After a form is submitted, I wanted to change several fields to READ ONLY for all other users, except the Administrator user role.
  2. From a field that is currently set to READ ONLY, I only want a specific user to be able to edit and update that specific field ONCE.  Once that field is set and updated, I want the field to not be editable by that user again (but still editable by the Admin)

For question 1.  I saw

add_filter('frm_setup_edit_fields_vars', 'frm_set_read_only', 20, 3);
function frm_set_read_only($values, $field, $entry_id){
	// If on the back-end, keep fields editable
	if ( FrmAppHelper::is_admin() ) {
	  return $values;
  	}

	// If on front-end, make specific fields read-only
        if ( in_array( $field->id, array( 1558,554,555,556 ) ) ) { 
	   $values['read_only'] = 1;
	}	
	return $values;
}
The above sets the fields read only from the start, so I cannot edit the form sections at all 
because they are pre-set to read only.  I wanted it to change to read only AFTER the user submits
their form.  


For question 2.  I am at a complete loss.  I was thinking something along the lines of a function
function check_if_set () {
  if (!isset(specific field name here) {
    then specified users can edit that specific field
  }
}

I believe this way that the function will allow that field to be set only once, since after the update that field would be set and that if statement would render that field not editable again.

 

Sorry, for asking for this... I scoured the knowledge-base and the community questions the past 3 days and little over the weekend to figure it out.  This is driving me nuts!  Any help or pointing in the right direction would help!

Why don't you add a check to make sure the field doesn't have a value before setting it to read only? If the field is empty, allow it to be edited, if now, make it read only?

Thank you for your response... that will work sort of... So I got everything figured out up until setting that specific form_id to read_only.

add_filter('frm_setup_edit_fields_vars', 'frm_set_read_only', 20, 3);
function frm_set_read_only($values, $field, $entry_id){
// If on front-end, make specific fields read-only
$field_id = FrmField::get_id_by_key('request');
if(isset($field_id)){
$field_id['read_only'] = 1; // this part I don't quite get
}
return $values;
}

You were more on the right track before. The code you have now won't work. You're already getting the field ID passed to you in the $field object.

It helps to examine the data you have available to in the $field object. One of the screen prints shows the 13 members contained in the $field object. You have $field->field_key available to you. This goes back to your other question about dev to prod environments.

The read only part is in the field_options array. You would set it to 1 using $field['field_options']->read_only = 1. But, because the frm_setup_edit_fields_vars passes the $values array back to Formidable and will ignore anything you set in the $field object, you have to set the field's read only attribute by using $values['read_only'] = 1. (see screen print)


Attachments:

thank you vfontjr!

 

so after reading your comments I figured out the best way to get what I want to achieve is to set a field to read only if it has been set.  is there some sort of hook for formidable forms that allows you to once a form field is set and submitted or updated to change that field into read only?

Discussion closed.