So I have a create form which has a radio field. Once this create form is submitted the user can edit the form later via a link. The radio field is a custom field added to my CPT.
What I'm wanting to do is change the radio field to hidden field on the edit form. I can add the hidden field easily enough but I need to somehow set the default value to be the same value set from the radio field previously.
If you could please show me how to do this I'll be able to do it next time.
The simplest way to achieve this is to continue with the radio field in the edit form, but hide it with CSS.
(A hidden input is no more secure inasmuch as it can also be revealed and modified with the browser dev tools.)
You can provide the existing value as a default value for your generic hidden input (which will need the same post meta key; Types custom fields are stored in wp_postmeta with a 'wpcf-' prefix, e.g. a field with slug of "priority" would be stored as "wpcf-priority") using a shortcode to provide the existing field value (e.g. using the wpv-post-field shortcode: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-field).
The problem with this approach is that generic field values are discarded after form submission completes. If you want to save the value you can either use the Forms API (e.g. the cred_save_data filter: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data) to manually save the field value after the form has submitted.
Or you can switch to the Advanced Editor for the form. The generic field includes JSON options, and you can add the option "persist":1 to the existing options which will tell Forms to save the field value.
However, all of the above seems redundant.
If you are hiding (one way or another) the field because you do not want users to be able to change its value, the you can simply omit the field from the form entirely: the original value will be unchanged.
If you are hiding (one way or another) the field because you do not want users to be able to change its value, the you can simply omit the field from the form entirely: the original value will be unchanged.
The only reason why I need it is because the edit form has a conditional that displays other fields based on what the value of the radio is. Is there a way I can achieve this without having the radio field in the edit form?
The conditional display in forms is evaluated on the front end using JavaScript, but it sounds like you could use the wpv-conditional shortcodes (which are evaluated on the server when generating the page) to show or not certain form fields.
You would need to use the Advanced Editor for the form to add the opening and closing wpv-conditional shortcode (to wrap the fields you want to selectively display), and you'll need to add them manually.
I assume the custom radio field "page-type" is created with Toolset Types plugin, Types plugin will add prefix "wpcf-" before the field slug, so you can use "wpcf-page-type" in the conditional shortcode, like this:
I have tried using the conditional groups but this only seems to work if the radio field is included in the edit form too. The whole idea is that the radio is hidden or not in the edit form.
Using css to hide the radio wont work as someone can simply inspect console, make it visible again and change value.