PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

pre-populating hidden form field problems.

  1. I am trying to pre populate a hidden form field.

    I've tried using a shortcode and php. Neither work.

    shortcode: [plexus var="agent" /]

    php: <?php plexus_information("agent"); ?>

    When I input the shortcode or the php code above and save it, the only thing that is saved is this: (Image linked).

    http://www.flickr.com/photos/fallenheroescar/4047270713/

    Both the shortcode and the php are working elsewhere in this website.

    Posted 12 years ago on Monday October 26, 2009 | Permalink
  2. Robert,
    I am not sure this is still an issue give your last response to the following post:
    http://forum.gravityhelp.com/topic/random-chanracters-in-hidden-field

    Let me know if you still need help with this.

    Posted 12 years ago on Tuesday October 27, 2009 | Permalink
  3. Alex,

    Yes, this problem belongs to a different form being used on a different website. It is still a problem.

    This problem with this form is with pre-populating a form field with data. The other issue was with a form was passing data to the Thank You message.

    Posted 12 years ago on Tuesday October 27, 2009 | Permalink
  4. In the Dynamic Field Population

    "In version 1.1.3 we introduced the ability to pass data from the form to the redirect page of your choice. In version 1.2 we have taken that a step further with the ability to pre-populate form fields using query string parameters, filters, shortcode or function call."

    So how do I pass the shortcode of [plexus var="agent" /] to the field?

    This shortcode is available on every page of our website.

    Posted 12 years ago on Tuesday October 27, 2009 | Permalink
  5. Robert,
    When we say you can populate a form field using the shortcode, we meant using the Gravity Forms shortcode. (i.e. [gravityform id=xxx field_values='parameter_name=value']).

    To dynamically populate a GF field with the value from your shortcode, you will need to use one of the hooks. You can follow the instructions I sent you in this post:
    http://forum.gravityhelp.com/topic/random-chanracters-in-hidden-field.
    You will just need to replace the uniqid(); call with the value of your shortcode.

    I hope this helps.

    Posted 12 years ago on Tuesday October 27, 2009 | Permalink
  6. You also have to be sure that the field has been set to allow data to pre-populate it. Go to the Form Editor, edit the Field and select the Advanced tab and make sure the "Allow field to be populated dynamically" checkbox is checked and that you assign it a parameter name.

    Then to populate the field you need to use the Gravity Forms function call and the Gravity Forms shortcode as Alex mentioned above.

    Ex.

    [gravityform id=xxx field_values='parameter_name=value']

    I'm not sure what this plexus shortcode and function call you are referring to is.

    Posted 12 years ago on Tuesday October 27, 2009 | Permalink
  7. Actually robert, I just finally figured out what you are trying to do.

    You can't use a shortcode or PHP function call where you are trying to use it. You don't pass someone elses shortcode or function to the field, you use Gravity Forms shortcodes or function calls to pass the data to the field.

    In this screenshot:

    http://www.flickr.com/photos/fallenheroescar/4047270713/

    You are trying to place PHP or a shortcode in the Parameter Name field in the Field Settings. This isn't what this is for. It's a text field, it isn't going to run PHP or parse the shortcode. It's a parameter name, it is a text field.

    The Parameter name is so you can give that field a variable name that you can then target using PHP on the front end, most likely from your themes Functions.php file.

    You would have to give the field a parameter name such as "transactionid" or "uniqueid" or whatever you want to call it (without the quotes).

    Then in your functions.php file you would use the code snippets Alex has given you in one of your support threads that showed you how to populate that field by targeting that parameter name.

    Alex gave you step by step instructions in this thread:

    http://forum.gravityhelp.com/topic/random-chanracters-in-hidden-field

    Posted 12 years ago on Tuesday October 27, 2009 | Permalink
  8. Carl,

    The instructions that Alex gave me are for a completely different issue (that has been solved), This issues has nothing to do with the other one. The form being used for this issue is on a completely different website.

    I guess what I am not understanding is this part of the product feature description.

    "In version 1.2 we have taken that a step further with the ability to pre-populate form fields using query string parameters, filters, shortcode or function call.""

    How do I PRE populate a field using a shortcode?

    If I can only use GravityForm shortcodes and no other WordPress shortcodes to pre populate fields then shouldn't the feature description say that? Right now the way it reads it makes people think that they can use any WordPress shortcode to pre-populate any field which if I understand you correctly is not the case.

    Thanks.

    Posted 12 years ago on Tuesday October 27, 2009 | Permalink
  9. You pre-populate a field using the Gravity Forms shortcode in a page or post.

    Here is the shortcode:

    [gravityform id=1 field_values='firstname=Carl']

    This shortcode would display a form id 1 and prepopulate the field with the parameter name "firstname" with the value "Carl".

    Our description is accurate, we provide ways to pre-populate the data using query string parameters, API filter, shortcode or function call. We don't control or have anything to do with shortcodes created by other plugins.

    In order for shortcodes to work it has to be processed by WordPress itself. Gravity Forms doesn't process the shortcodes, which is why placing a shortcode in the parameter name isn't going to work (not to mention thats a name field and not a value field).

    Typically a shortcode also has a function call that can be used. Whatever you are trying to do with another shortcode/function call can be accomplished using the api filters to do so and setting the value of the field to the output of the function call (plexus) you are trying to do.

    What you are trying to do is exactly what the API filters hooks are designed to be used for.

    Posted 12 years ago on Tuesday October 27, 2009 | Permalink
  10. So if I wanted to pass:

    <?php plexus_information("agent"); ?>

    Would this work in my function.php?

    add_filter("gform_field_value_agent", "populate_agent");
    function populate_agent(){
    return .plexus_information("agent").;
    }

    My agent text box would then be ticked to allow dynamic population, and called 'agent'.

    Am I on the right track here?

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  11. Robert,
    Yes, you are on the right track. I think you are almost there. Use the following code snippet in your functions.php instead. (extra dots (.) were removed)

    add_filter("gform_field_value_agent", "populate_agent");
    function populate_agent(){
    return plexus_information("agent");
    }
    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  12. hhhmmm... the field is still blank. Does the Field Label also have to be called "agent"?

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  13. Hey Robert, I just noticed the forum had added BR tags in Alex's code sample above. You didn't include those in your code did you?

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  14. Carl,

    Nope, no BR line breaks in the code.

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  15. Hello Robert, Try this test code snippet which simply inserts a text value into the field and let me know if it works. I just tested it on my test site by placing it in my themes functions.php file and it is pre-populating the field value as it should.

    add_filter("gform_field_value_agent", "populate_agent");
    function populate_agent(){
    $agent_value = "Test";
    return $agent_value;
    }

    I placed the above code snippet on my test site and you can see it pre-populate the value here:

    http://www.carlhancock.com/test/

    You will see the textarea on that form has "Test" as the value, it is being pre-populated by the code snippet above.

    Try this test snippet to see if it does the same for you so we can then determine why your original code didn't populate the field value.

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  16. Carl,

    Yup, that put "Test" in the field.

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  17. If it is populating the field that means the filter is working as intended and the issue has to do with the function you are trying to call as the value. Double check that your plexus_information("agent") is in fact returning a value, try calling it in your theme somewhere by itself and see if it outputs the expected value on the page.

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  18. Carl,

    We call it on every singe page of our website and it's works fine. We use the php to place it in the sidebar

    <?php plexus_information("agent"); ?>

    and the shortcode to place it in certain pages.

    [plexus var="agent" /]

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  19. What exactly does that function output? Can you post an example of what that function call outputs here?

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  20. It outputs a 5 digit agent id number. Only numeric digits.

    For example: 86740

    Posted 12 years ago on Wednesday October 28, 2009 | Permalink
  21. Hey Robert, can you email me the code that makes up the plexus_information PHP function so that we can take a look at it? There is something with how that function is utilized that is preventing it from working within the context of the filter.

    If you can send us over the PHP code as an email attachment, we can take a look and see if we notice anything that can be changed so that it will work. You can send it to carl -at- rocketgenius.com

    Thanks!

    Posted 12 years ago on Thursday October 29, 2009 | Permalink
  22. Caril,

    I'll just edit our our database URL info and post it below.

    <?php
    /*
    Plugin Name: Plexus Core
    Plugin URI:
    Description: Gather specific information from a Plexus database for use in browser cookies
    Version: 2.0
    Author: Robert Basil
    Author URI: http://www.plexusworldwideinc.com
    */
    
    /*  Copyright 2009  Robert Basil  (email : robert@plexusworldwide.com)
    
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    */
    
    /*  This function is the core of the plug-in.  Place a call to this function at the top of your
     *	theme's 404 page template (404.php).  Make sure the call is AFTER any headers are sent to
     *	avoid an error.
     */
    function plexus_initialize() {
    	$url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];							//First we parse the URL requested
    	$sPath = substr($url, -(strlen($url) - strlen(get_bloginfo('url')) - 1));						//Based on the URL requested and the known page URL, we now know the request
    
    //	plexus_cookie($sPath);																			//This function will store whatever the user entered in the last part of the URL in
    																									//a cookie called "plexus_data"
    	$dataurl = "http://www.database-url-removed-for-security.com/plexus/err404.asp?site=" . $sPath;
    setcookie("tester", $dataurl, time() + 36000);
    
    	$datastring = file_post_contents($dataurl);
    	plexus_populate($sPath, $datastring);
    }
    
    function plexus_populate($id, $everything) {
    	$data = explode("|", $everything);
    	$dummy = $data[0];
    	$agent = $data[1];
    	$name = $data[2];
    	$email = $data[3];
    	$phone = $data[4];
    	$photo = $data[6];
    
    	if($agent != "Not Found") {
    		setcookie("plexus_ID", $id, time() + 36000);
    		setcookie("plexus_Extra", $dummy, time()+36000);
    		setcookie("plexus_Agent", $agent, time() + 36000);
    		setcookie("plexus_Name", $name, time() + 36000);
    		setcookie("plexus_Email", $email, time() + 36000);
    		setcookie("plexus_Phone", $phone, time() + 36000);
    		setcookie("plexus_Photo", $photo, time() + 36000);
    	}
    }
    
    function plexus_shortcode($atts) {
    	$atts = shortcode_atts(array('var' => ''), $atts);
    	return get_plexus_information($atts['var']);
    }
    
    function get_plexus_information($info)
    {
    	switch(strtolower($info)) {
    		case 'id':
    			return $_COOKIE['plexus_ID'];
    			break;
    		case 'agent':
    			return $_COOKIE['plexus_Agent'];
    			break;
    		case 'name':
    			return $_COOKIE['plexus_Name'];
    			break;
    		case 'email':
    			return $_COOKIE['plexus_Email'];
    			break;
    		case 'phone':
    			return $_COOKIE['plexus_Phone'];
    			break;
    		case 'photo':
    			return $_COOKIE['plexus_Photo'];
    			break;
    		default:
    			return false;
    			break;
    	}
    }
    
    /*  These functions will echo back the appropriate field from the cookie
     */
    function plexus_information($info)
    {
    	echo get_plexus_information($info);
    }
    //add_shortcode('plexus', 'plexus_shortcode');
    add_shortcode('plexus', 'plexus_shortcode');
    
    /* Miscellaneous function to allow us to use PUT methods to retrieve information
     */
    function file_post_contents($url,$head=false) {
        $url = parse_url($url);
    
        if (!isset($url['port'])) {
          if ($url['scheme'] == 'http') { $url['port']=80; }
          elseif ($url['scheme'] == 'https') { $url['port']=443; }
        }
        $url['query']=isset($url['query'])?$url['query']:'';
    
        $url['protocol']=$url['scheme'].'://';
        $eol="\r\n";
    
        $headers =  "POST ".$url['protocol'].$url['host'].$url['path']." HTTP/1.0".$eol.
                    "Host: ".$url['host'].$eol.
                    "Referer: ".$url['protocol'].$url['host'].$url['path'].$eol.
                    "Content-Type: application/x-www-form-urlencoded".$eol.
                    "Content-Length: ".strlen($url['query']).$eol.
                    $eol.$url['query'];
        $fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);
        if($fp) {
          fputs($fp, $headers);
          $result = '';
          while(!feof($fp)) { $result .= fgets($fp, 128); }
          fclose($fp);
          if (!$head) {
            //removes headers
            $pattern="/^.*\r\n\r\n/s";
            $result=preg_replace($pattern,'',$result);
          }
          return $result;
        }
    } 
    
    ?>
    Posted 12 years ago on Thursday October 29, 2009 | Permalink
  23. Robert,
    Based on your function, I don't see why it wouldn't return the correct value inside the filter. Is there any way you could give me temporary access to your WP admin so that I could take a closer look at it? If so, please email them to alex[at]rocketgenius.com.

    Posted 12 years ago on Friday October 30, 2009 | Permalink

This topic has been resolved and has been closed to new replies.