Is it possible if I'm in a post on my blog and I click on a link that says submit (or what ever) and that link forwards me to a gravity form that the post title of the post where I was will be automaticly put in the form as a field?
Is it possible if I'm in a post on my blog and I click on a link that says submit (or what ever) and that link forwards me to a gravity form that the post title of the post where I was will be automaticly put in the form as a field?
You can only get the referrer url as a default value in a field, not the page name of the referrer url.
What you could do is in your link to the form, pass the page name as a query string parameter to the form. Then in your form setup a field that can be populated dynamically using that query string parameter.
This can be done by adding the link to the form in your post template file, and using PHP set it up so it passes the post name as a query string parameter value to the page that contains the form.
See this post on using the query string to send values to a form:
http://forum.gravityhelp.com/topic/sending-dynamic-form-variables-to-another-form
@Carl,
Thanks for the reply. I'm starting to get my way around with php. So I hope I will manage this.I'll try and comeback as it works :-)
What I probably need is this query string: <?php post_title; ? >
What php code do I need to get it sent to another page. Who has a tip for me to find info on that?
Or should I already use a form on the first page where people click the link?
I can show you where I need it: http://proefcollege.info
If you go here you see in the post the link inschrijven. If you click that link you go to a form where people have to ad a name and some more. I also want the name of the post (= the referrer post name) sented in that form to the administrator of the website.
You can pass the post id via URL.
So the URL for Proefcollege with post id 3 would be http://proefcollege.info/inschrijven-2/?proefcollege=3. You could easily achieve this within your loop.
Just change:
<a href="http://proefcollege.info/inschrijven-2/">Inschrijven</a>
to:
<a href="http://proefcollege.info/inschrijven-2/?proefcollege=<?php the_ID(); ?>">Inschrijven</a>
In your themes functions.php add the following snippet:
add_filter( 'gform_field_value_proefcollege', 'populate_proefcollege' );
function populate_proefcollege(){
$proefcollege= get_the_title($_GET["proefcollege"]);
return $proefcollege;
}
@Jan Egbert,
Thanks for the reply. I was working on it today, but it only shows this: Embed URL: .../ The dots and the slash are a link to: http://proefcollege.info/inschrijven-2/?proefcollege=%3C?php%20the_ID();%20?%3E. If I click that I will go to: http://proefcollege.info/inschrijven-2/
But I want to know the title op the post the person was coming from when they came to http://proefcollege.info/inschrijven-2/
Do you know what is going wrong?
Perhaps I know what is going wrong. Perhaps I didn't explain well what I want.
I have a site with posts on the front: in each post there is the link:
'Inschrijven'
With this link they get to the form that is on http://proefcollege.info/inschrijven-2/. I want the title of the post that is on the front of the website into the form.
Jan's example above outlines how you would do this.
You have to pass the id of the post they are coming from in the link to the form, and then you would use the API hook to read that id, get the title of the post, and then populate the field with it.
@Carl, I think I do understand what you mean. I will try it. And will come back on it.
I have looked at it, but I don't understand what I'm doing wrong. Should I use a new form field in my form I mad that gets the url of the post?
Thanks guys,
I know what went wrong. I had to tell in my form the things below.
Allow field to be populated dynamically (?)
Parameter Name:
I did that and now it works!
Will it be possible to get beside the Post title, also get the info of a custom field that is used?
That it will be something like: <a href="http://proefcollege.info/inschrijven-2/?proefcollege=<?php the_ID(); ?><?php get_custom_field(); ?>">Inschrijven</a>
The post ID is the key to everything that is related to that single post. Calling for a custom field as you are trying above will only get custom fields for the page called Inschrijven.
Example: If you want to pre-populate a hidden field called price you need to enable that field to be pre-populated and add the following snippet to your themes' functions.php.
add_filter( 'gform_field_value_price', 'populate_price' );
function populate_price(){
$price = get_post_meta($_GET["proefcollege"], "price", true);
return $price;
}
Function reference for get_post_meta() : http://codex.wordpress.org/Function_Reference/get_post_meta
The snippet given above by Jan Egbert IS NOT INCLUDED in documentation under Hooks and Filters. It took me nearly 2 hours to find this information. This should definitely be included in the documentation, as it is referenced in a gravity forms 'help bubble' but not explained anywhere other than here (unless I missed something!)
There are a bunch of undocumented API hooks and filters that we plan on providing more documentation for in the near future.
Thanks for the clarification Carl. Any chance you could give me the next best thing, the php file where I can find reference to said hooks and filters to figure it out on my own?
I'm not sure what you mean, if you have Gravity Forms you already have the PHP. The hooks and filters exist within the plugin code itself across multiple files. They aren't contained in a single file.