Skip Navigation

[Resolved] Default select field to one of its own option values

This support ticket is created 6 years, 8 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: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#790611

I have this form: 'Request'. It is actually a child to: Exec. Customer, & Customer-contact. When I created the 'Request' form, these parent fields were generated at the time the form was created. I hide the Exec field to set it later based on other user input, but I'm using the Customer and Customer-Contact fields in the form.

I just want to default the Customer and Customer-contact fields to a value found in their list of options (which is cred generated). THIS IS SO ELEMENTARY TO FORM DEVELOPMENT. I DON'T UNDERSTAND WHY IT'S TAKEN TWO DAYS TO FIND LITTLE THAT WORKS!! I (For some reason I can't even get ANY js to work)

#792135

Hello,

Please elaborate the question with more details:

default the Customer and Customer-contact fields to a value found in their list of options (which is cred generated)

What is the value found in their list of options?
How does CRED generate it?

I assume you are using CRED shortcode [cred_field] to render the parent Customer and Customer-contact fields.

Please check our document of shortcode [cred_field]:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
1) You can set field default value with attribute "value", for example:
[cred_field value="1234" ...]

2) You can set the field default value with URL parameter:
urlparam. Optional. A URL parameter to set default value. For example, a URL with the additional parameter ?some_param=some_value will set the some_value value to some_param.

#816680

When I created the form, the wizard brings them into the editor.

How do the parent fields normally get set? I'm hiding the parent fields because I couldn't set a default value on the parent field so I created VIEWS where I had conditional control in the loop enabling me to set the default.

In order to maintain relationship, the HIDDEN parent fields need to be set based on the values the user selected in the view fields.

It doesn't work when I set the field value (of course if I could set the field by value=' ', I wouldn't need the view-serogates):

[cred_field field='_wpcf_belongs_exec_id' value="[wpv-post-id]" select_text='--- not set ---' class='form-control' output='bootstrap']
-OR-
[cred_field field='_wpcf_belongs_exec_id' value="wpv-post-464" select_text='--- not set ---' class='form-control' output='bootstrap']
-OR-
[cred_field field='_wpcf_belongs_exec_id' value="Mark E. Duncan" select_text='--- not set ---' class='form-control' output='bootstrap']

Most of what I can find on the subject in your documentation is out-of-date! This is a common place feature of a form. I don't understand why it is such a mystery.

I can't get a hold of the <option> e.g. <option value="frustrated" selected="selected">Frustrated</option>

#837794

It is not clear:
1) How do you setup the CRED form? is it a CRED form for creating child post?
2) Where do you put your CRED form? is it a single parent post?

If both of above are correct, you can try this simply:
output the Views shortcode [wpv-post-id] directly, make sure it is outputting the current parent post ID correctly
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-id

If it is correct, you can use it as "value" attribute, for example:
[cred_field field='_wpcf_belongs_exec_id' value='[wpv-post-id]' select_text='--- not set ---' class='form-control' output='bootstrap']

If you still need assistance for it, please provide a test site with the same problem, I can setup a demo for you.