Skip Navigation

[Closed] conditionally make fields readonly

This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 7 replies, has 2 voices.

Last updated by Jamal 3 years, 9 months ago.

Assisted by: Jamal.

Author
Posts
#1929395

I have an update user form where the user will be able to update his details.

I have radio button for user status. (approve ,reject) and i have organization field . I would like to make the organization field readonly only if the radio button checked to rejected

#1929471

thank you, Jamal. I will contact you once I set up the form.

#1929649

Awesome. Thank you!
I'll set this ticket as waiting for your reply until you prepare the form.

#1930609

I have created the form. and I have created 2 users both with 12345 password. One approved and the other one is rejected.
The organization should be readonly for the approved person and active for the rejected one.
Log in using these account and access the page
hidden link

#1932669

Hi Jamal,

Any updates on this?

#1935057

My apologies for the late reply, but I do not work on Wednesdays and Thursdays.

It turned out that wpv-conditional shortcodes are not supported inside forms. Also, we cannot use Forms conditional groups on a field(status) that does not exist in the form.
To work around this, we'll use two forms, one for Rejected users and the other for Approved users. I cloned the existing form and wrapped the organization field inside a disabled field set:

<fieldset disabled>
	<div class="form-group">
		<label>[cred_i18n name='org-label']Organization[/cred_i18n]</label>
		[cred_field field='org' force_type='field' class='form-control' output='bootstrap']
	</div>

</fieldset>

Then, I used a Fields&Text block to display one of the forms based on the current user status:

[wpv-conditional if="( '[types usermeta='request-status' current_user='true'][/types]' eq 'Rejected' )"]
	[cred_user_form form='update-user-form-readonly']
[/wpv-conditional]

[wpv-conditional if="( '[types usermeta='request-status' current_user='true'][/types]' eq 'Approved' )"]
	[cred_user_form form='update-user-form']
[/wpv-conditional]

Additionally, I would like to note some "issues" that you may want to address.
- Every user can update his data(status, organization, etc.) on his profile page.
You may want to disable access to it hidden link
Or you may want to make the status field only available for admins using The Toolset Access https://toolset.com/course-lesson/access-control-for-custom-fields/

- For more security, you may want to add custom validation for these forms. And make sure the organization field is only updated when the current user has all the requirements(is not rejected). https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

#1936543

Many thanks Jamal for your suggestions. I will work on it and I will come back to you.

#1936585

Awesome! I am glad I could help.

I'll set this ticket as waiting for your feedback, which will keep it open for 3 weeks until you mark it as resolved or you get back to us for further assistance.

All the best,
Jamal

The topic ‘[Closed] conditionally make fields readonly’ is closed to new replies.