I looked into the 'Default Value' functionality in the 'Advanced' tab of an input field, and you're right, there aren't any hooks to be able to inject a url parameter.
I think you have 2 options (and one is better than the other):
1) Write an additional hook for yourself in ./common.php 'replace_variables_repopulate()' line 665 where you look for a url parameter of your choice. Not recommended in my opinion because when it's time to upgrade you'll lose that functionality.
2) Use JavaScript. Here's a snippet that you can put into your page template. (Whichever page template holds your contact form). You could even put this into header.php because it's pretty harmless when a contact form doesn't exist:
<script>
jQuery(document).ready(function() {
var previousName = "<?= urldecode($_GET['previous_name']); ?>";
jQuery('.gform_wrapper input:eq(0)').val(previousName);
});
</script>
This does 2 things. The first line will look for the url parameter named 'previous_name'. It'll assign a URL decoded (stripped of %20 and things like that) string into a JavaScript variable named 'previousName'. Next it'll look for the gravity form wrapper and its FIRST input field. Once it gets it, it's going to inject the value in 'previousName' into the text field.
A couple things here... You can modify that jQuery selector if the first text field isn't the proper one to inject into. (I did it that way because you mentioned it was the first field). Otherwise you'll have to assign a custom class to your text field in the Advanced tab of Gravity Forms Edit and then the selector would be something like, "jQuery('.gform_wrapper .my_custom_class_name')".
On the previous page (which renders the button and url) just make sure you build your URL to include the parameter name 'previous_name' and the value can be the post/page title (which is the missing person's name, it sounds like).
Have fun!
Posted 12 years ago on Sunday January 29, 2012 |
Permalink