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.

Populate fields with custom fields values

  1. Muhammad Mustafa
    Member

    I am new to gravity forms and I must first admit that its awesome!
    I've been working on my first form for a while and everything seems working great expect one last function I am trying to execute with no success so far.
    I've 10's of pages with 5-10 products per page, each product's name & price is defined in custom fields as:
    item1, price1 - item2, price2 - item3, item4- .......
    Assuming that item1 & price1 values are: example_product & $99
    In my form I've 2 hidden fields that can populated dynamically named 'name' & 'price', when I link to my form page from the products' page using this link (example.com/form-page?name=example_product&price=$99) and submit the form, entry successfully and store both 'example_product' and '$99' values and I can find them stored in the database without any problems.
    Now, rather than injecting the values of product name and price to 100's of links for 100's of products in each single page, I am after an easier way to auto get the custom fields values automatically and populate these 2 hidden fields within my form, I've searched through the form and the documentation for a solution and didn't found anything but this:
    http://www.gravityhelp.com/forums/topic/using-custom-fields-to-populate-hidden-fields
    I've tried the solution posted there but didn't worked for me, he have his form in the same page contains the custom fields, while for me they are 2 different pages, didn't worked for me because of that? maybe!
    BTW, if you'd be able to add the ability to populate the fields with chosen custom fields from origin post as within the default value option it gonna be one very amazing added features to gravity forms, personally, I'd love to see such a feature soon to save myself sometime, maybe someone's time in the future too :)

    Posted 13 years ago on Tuesday April 26, 2011 | Permalink
  2. Hi Muhammad,

    If you know the post ID of the page that is storing your custom fields, you can use the get_post_custom() function to retrieve those values. Something like this:

    [php]
    get_post_custom($post_id, 'stored_value', true);

    If this information not quite what you're looking for, could you clarify a bit on the exact setup and why would not have access to the post ID?

    Posted 13 years ago on Tuesday April 26, 2011 | Permalink
  3. Muhammad Mustafa
    Member

    Thanks for your reply David, it didn't worked :(
    However, again, here's what I am trying to do, I've simplified the process to the max:

    In my site I've 2 pages, page A and page B:
    - Page A contains some products I am selling, lets say 2 products, xproduct and yproduct
    - Page B contains an order form made using Gravity Forms

    - Page A have 2 custom fields contains the product code of these 2 products as following:
    -- Custom Field #1 >> name: xcode, value: p1xcode
    -- Custom Field #2 >> name: ycode, value: p2ycode
    - Page B have 1 hidden field named code populated automatically by the (?code=value) in the incoming URL

    - When customer would like to purchase xproduct from page A he click a 'Buy Now' link next to it, where this link do contain the (?code=p1xcode) and forward to page B, the form filled successfully with the hidden filed populated with 'p1xcode'
    - Same thing applies to the other product, so, when customer would like to purchase yproduct from page A he click a 'Buy Now' link next to it, where this link do contain the (?code=p2ycode) and forward to page B, the form filled successfully with the hidden filed populated with 'p2ycode'

    I believe its so clear so far, and everything is working great till here
    What I want to do is: Instead of hard-coding (p1xcode) and (p2ycode) manually for all 'Buy Now' links for each individual product, I'd like the hidden field in gravity form to AUTO get the value of specific custom field in the origin page
    So:
    Instead of "?code=p1xcode"
    It'd be "?code=custom_field_name" ... (or whatever tweak of code it takes)
    The Result: Hidden Field in the Gravity Form populated with the value of that custom field automatically
    What we are talking about here is NOT only Page A, but 10's of pages ALL pointing to the same page/form for completing the purchase...

    I believe I made it simple enough and explained the whole process, don't know if this is enough and achievable of not, but hopefully it is :)

    Posted 13 years ago on Wednesday April 27, 2011 | Permalink
  4. Are you what you are doing is linking to a form and you want to pass information from the page you are linking from to the form and have it populate a hidden field?

    Ex.

    Page A has a custom field value of Y
    Page A has a link to Page B containing the Buy Now link
    Page A passes custom field value & to Page B
    Page B dynamically populates hidden field with value of Y passed from Page A

    Is this correct?

    If so what you want to do is pass the value in the query string to the page containing the form. Then you want to setup your form so it has a hidden field on it, edit that hidden field and select the Advanced tab and set the field to be populated dynamically. Give the field a parameter name after doing so, the parameter name is what you use to pass data to it in the query string. So for example if you give it a parameter name of "code" then you would pass data to it view the query string by passing the value to it like so:

    http://mydomain.com/myform?code=MYVALUE

    You'd then add a link in Page A to Page B passing ?code=MYVALUE in the query string. You'd have to use the code David referenced to get the custom field value and pass it in the link.

    The information in the link you referenced in the first post does work, and what I described above also works. But beyond providing you with information on how to do it we can't implement it for you so there could be some minor issue with it not being implemented correctly which is where the problem is.

    Posted 13 years ago on Wednesday April 27, 2011 | Permalink
  5. Muhammad Mustafa
    Member

    Thanks for your reply Carl

    As I stated earlier, I've already followed the same steps you posted here, and again it works only if I inject the value in the URL myself, the code listed in the other thread as stated before would work ONLY if you have the form in the same page, not in a separate page like my case here
    However, I managed to find a solution myself and it worked, in case anyone here like to do the same, use a plugin called "Custom fields shortcode" it would let you get any custom field value using a simple shortcode and it worked for me with less code effort
    This thread can be marked as resolved now :)

    Posted 13 years ago on Friday April 29, 2011 | Permalink

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