Skip Navigation

[Resolved] Setting a default value for a cred form field

This support ticket is created 7 years, 1 month 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 7 replies, has 2 voices.

Last updated by brentC 7 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#593239

Tell us what you are trying to do?
I have a site with domains for sale. Each domain gets its own page. I have a cred form on each of the domain pages to allow a user to inquire about that domain. I have a field for the domain and I want that to be filled in automatically based on the current post. The current post is a custom post type called "Domains" created with toolset types. The title of that post is the domain name. Alternatively, we can get it from the URL since the URL contains the domain name.

What is the link to your site?
hidden link
hidden link

The data I want auto-populated in the Domain field is the "女.com" or "男.com" part.

I saw we can do it with URL parameters but my pages have the domain in the URL path itself, not as a parameter.

Any way to make this happen?

#593280

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Brent

If you are displaying a CRED form on a page where you want to use the title of that page within the form (to set a value attribute) you can simply use the [wpv-post-title] shortcode.

The context for that shortcode is the page itself where the form is diplayed.

I think that is what you were asking, yes?

#593288

Thanks for the reply. Yeah, I tried that after seeing it in some other support requests... but it doesn't work for me. I changed the value='' part that was created by default to value='[wpv-post-title]':

[cred_field field='domain-inquiries-domain' post='domain-inquiry' value='[wpv-post-title]' class='form-control' output='bootstrap']

but when rendered on the page I get nothing in the "Domain" field and weird extra stuff showing up after the field:

' class='form-control' output='bootstrap']

which is basically the stuff after the shortcode.

I tried various versions of single and double quotes and nothing works. Am I missing something?

One note: I have a custom template created in PHP for the Domain content type and I'm showing the cred form in that template with this PHP:

echo do_shortcode("[cred_form form=\"domain-inquiries-form\"]");

Is there something about doing a shortcode from within a shortcode or is there some cred specific way to execute shortcodes from PHP?

#593293

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Brent

I think I saw something similar a few days ago with a colleague, where the advice was to not use do_shortcode to render CRED forms in PHP templates and to insert the form directly using the cred_form function.

It takes one attribute, form, with the slug of the form in question, e.g.

<?php cred_form( form="form-slug" ); ?>

Can you try inserting your form like that and see if the title shortcode then works?

If not I'll dig deeper.

#593302

Thanks for the idea. I changed it to:

cred_form("domain-inquiries-form");

and put value='[wpv-post-title]' in the cred_field and I'm getting the exact same (bad) output.

#593370

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Brent

I'll do some testing locally to see what to expect and get back to you.

#593475

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Brent

I set up a site locally to test this where I directly render a form in a PHP template using cred_form( 'page-slug' ) and where I use [wpv-post-title] for the value attribute of one of the form fields and it worked as expected.

What kind of field is the form field in question? I was just populating a text field in my test.

#593576

I didn't have the "Views" plug-in installed, just types and cred... works like a charm even without using cred_form. Thanks!