Skip Navigation

[Resolved] Pass CPT field value to a CRED form on another page

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to know how to pass values into a CRED form on another page, or on the current page.

Solution: Use the "urlparam" attribute on any CRED field to set the value of that field using a URL parameter:

[cred_field field='contact-car' post='contact-form' urlparam='contactcarparam' class='form-control' output='bootstrap']

In your link to the other page, add the url parameter after the listing ID parameter the end of the URL:

<a class="btn btn-lg btn-primary single-contact-button" href="[wpv-bloginfo show='url']/contact/?listing-id=[wpv-post-id]&contactcarparam=[wpv-post-field name='wpcf-ownersvehicle_id']">Contact Us</a>

If you want to set the value of a field on the current page, use the [wpv-post-field] shortcode to access the raw field value:

[cred_field field='contact-car' post='contact-form' class='form-control' value='[wpv-post-field name='wpcf-ownersvehicle_id' id='$current_page']' output='bootstrap']

Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-shortcodes/
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field

This support ticket is created 7 years, 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Eric De Paep 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#554777

Hi,

I 'm working on a car dealer website. On my CPT layout page I want to have a button like on the classified reference site: hidden link But, instead of passing the advertiser / current user value to the CRED form, I want to pass one of the CPT's values (ownersvehicle_id) to the CRED form to prepopulate one of its fields.

Based on the reference site I used the following code:

<!-- For the link button -->
<p><a class="btn btn-lg btn-primary single-contact-button" href="[wpv-bloginfo show='url']/contact/?listing-id=[wpv-post-id]">Contact Us</a></p>
<!-- In the CRED form -->
<div class="form-group">
		<label>[wpml-string context='cred-form-Create content - Posts-9557' name='Wagen']Car[/wpml-string]</label>
		[cred_field field='contact-car' post='contact-form' value='[wpv-post-field name='wpcf-ownersvehicle_id']' urlparam='' class='form-control' output='bootstrap']
	</div>

But this doesn't work. I'm not sure about the shortcode to use for the CRED field value. Is there somthing else I'm missing?

Thanks

#554820

Hi, if you want to pass an argument into the CRED form page, you need to add it to your link's href attribute:

<a class="btn btn-lg btn-primary single-contact-button" href="[wpv-bloginfo show='url']/contact/?listing-id=[wpv-post-id]&contactcarparam=[wpv-post-field name='wpcf-ownersvehicle_id']">Contact Us</a>

Now when this link is clicked, the contactcarparam URL parameter will be set on the CRED form page. The CRED field should use the same urlparam attribute of 'contactcarparam', so that this value is automatically set in your form using the value from the URL.

[cred_field field='contact-car' post='contact-form' urlparam='contactcarparam' class='form-control' output='bootstrap']
#554837

Hi,

Thanks! That works great.

Now imagine I want to put the CRED form on the same page (the CPT layout page), what shortcode should I use in my form then?

Something like this?

[cred_field field='contact-car' post='contact-form' value='[wpv-post-field name='wpcf-ownersvehicle_id']' urlparam='' class='form-control' output='bootstrap']

or this

[cred_field field='contact-car' post='contact-form' value=[types field='ownersvehicle_id'][/types]' urlparam='' class='form-control' output='bootstrap']
#554862

You should use the wpv-post-field shortcode with an id attribute, so you can add a reference to the current post:

[wpv-post-field name='wpcf-ownersvehicle_id' id='$current_page']

More info about this:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field

#556500

Ok thanks.