Skip Navigation

[Résolu] Getting field values from custom post type into gravity forms

This support ticket is created Il y a 7 années et 1 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 5 réponses, a 2 voix.

Dernière mise à jour par Jim Il y a 7 années et 1 mois.

Assisté par: Nigel.

Auteur
Publications
#580553

Jim

I have a custom post type "products" setup and on the archive page the visitor can click a button next to each product that takes them to an order page.

This order page has a generic form build with Gravity Forms that needs to populate two fields with data from that product (the title and the price)

I have build a view that extracts the title and the price and I can show the title and proce on the form page but obviously I cannot get this data into the form field this way.

Is there a solution to this?

Any help is much appreciated
Thnx, Jim

#580616

Jim

I am already passing the post-id to the page with the form in the url:

mysite.com/orderform/?program=20

I know I can submit values through the querystring but I rather do not want to use that because it depends on the querystring and the price can be adjusted and also, if someone visits this page directly it does not have the values.

Anyone?

Must be something simple with a hook querying the db for the right values using the post-id (or should it be passed through post for this?) and then passing the values into the GravityForm by add_filter.

I know it can be done and I must be close, but I am not a programmer enough to code it.

Anyone??

#580997

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi Jim

Your ticket just popped up in the queue and I see it is nearly 3 days old. I'm not sure what happened, but first let me apologise for the delay in having someone respond to you.

Looking at your question, I must point out that custom coding is outside of our support policy, but let me see what I can do to help you.

I'm going to set up a local test site with a GF form and check what is required to pass fields to it from an existing post and I will get back to you soon.

#581012

Jim

Very much appreciated Nigel. Thnx

#581017

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi Jim

I created a rudimentary test site with a Products post type which has a title and includes a price custom field.

I have a View which lists products, and in the output section of that View alongside the title I have an order link.

That takes me to a page where I have my Gravity Form to order the product, which needs the product title and price fields to be pre-filled.

I use URL parameters for this as it is the most natural choice in this case and does not require any custom coding. (See the official GF documentation here: lien caché.)

You could use an alternative method to populate the fields using hooks, but you would still have to pass the post id to the form so that the form knew which product was being ordered, so you might as well pass the fields directly. Using hooks wouldn't solve the problem of anyone visiting the page directly because the form wouldn't know which product to order in any case.

In the GF form I checked "Allow field to be populated dynamically" for both fields and gave them parameters of "the_title" and "price".

So the link from my View to the page with the form needs to look something like this when output: mysite.com/orders/?the_title=PS4&price=399.99

I can generate that link like so in my Loop Output section:

<a href="<em><u>lien caché</u></em> field='price' output='raw'][/types]">Order [wpv-post-title]</a>
</a>

Note that I used the Fields and Views button to insert shortcodes for the post title and the price custom field (with no formatting).

That worked nicely on my test site.

If you want to try on your own site and let me know how you get on.

#581199

Jim

Thanks Nigel.

Yes I am aware of that solution like I wrote in my 2nd comment in this thread.

But you are right that the page would still need an Id to load the right product.

Because I do not want the visitor to be able to change the query string (and the price!*) I have decided to give up on this part of the wishlist.
I have spoken to the client and it is no problem for them to add a new page and order-form by hand.

* Although the form does not process the billing, I find it amateurish when the client sees the price set in the URL and beïng able to change it.