*** NOTE: FOR DEVELOPERS ONLY ***
Andy,
It took me a while to figure out how to solve the problem you asked about. Basically, you wanted to know if there was a way to retrieve values via code from the $entry array without having prior knowledge of the numeric input id's used as array keys.
For Example:
The value for the Phone Number field from a posted GForm might be retrieved with the following line:
$phone = $entry[19];
However, you would need to have prior knowledge that 19 is the id for accessing the phone number field for this GForm. You would prefer to access the value submitted for Phone Number with the following line:
$phone = $entry['phone'];
Perhaps the GravityForms guys can give some insight on this. Since I'm reviewing the GF plugin code to better understand the architecture for another plugin I want to create, I decided to take a stab at this.
Please review the new helper functions I created and the rest of this post to see how I was able to accomplish what you were looking for.
View New Code Page: http://www.pastie.org/1736319
**** DISCLAIMER ****
You will need to review this entire post to understand how to configure your GForm settings for this code to work. This code is provided AS-IS, works on my server and specific environment settings, uses id's based on my GravityForms setup, and may change if an update is made to the GF Plugin.
*************************
That said, I did add a lot of code comments and this very detailed post to help you modify the helper for your own use. While all the code is on one file, I recommend moving some of these methods to common locations as appropriate. You could also consider moving some of these fragments into their own namespaces.
** Improvement: LogConsole **
One major improvement in this updated code is you don't have to comment out all the LogConsole() lines. There are security and context checks in place now that will only run those logs if being called from debug-bar-console plugin as the site super admin.
** Setup Your GForm to Work with Test **
To get started, you'll need to do a few things on your GF configurations first:
1. GF User Registration Plugin is required. Make sure this is installed.
2. Go to Form Editor for the form you want to test.
- Make sure you have fields for the following:
- Username
- Site Name
- First Name
- Last Name
- Email Address
- Phone Number
Apply update to the GForm.
3. Locate GForm form_id
Take note of the form_id for this GForm. You can get this from the Form List Page. It's also in the querystring when viewing in the Form Editor as form_id. If your form_id is not 1, then you'll need to update the test method:
- BuildMockEntryArray( $form_id = 1 , [... other params .. ]) { }
Replace 1 with the ID that matches your form.
4. Go to GF User Registration Settings Page:
- Edit the User Registration Settings you want to test this GForm with. Create a new one if you don't already have one created.
- Select the GForm you want to use.
- Map the following Standard Fields:
- Username
- First Name
- Last Name
- Email Address
- Create 2 new Custom User Meta Settings:
- Site Name
- Phone
NOTE: Use the names for this test exactly as you see them. This is case sensitive.
- Map these values to your GForm Fields.
- Save your changes.
** Debug-Bar-Console Test will Only Work From Page Hosting GForm **
1. Testing this with debug-bar-console must be done on a page that has a reference to this GForm.
2. You must also be logged in as the site super admin. Add the GForm to a new page and go to the page in view mode.
3. From the page hosting the GForm, open debug-bar-console plugin
and Run the following line:
GFHeapTestHarness();
** Reviewing the Log Output: **
1. To verify numeric keys are matched to friendly named keys, locate the first Array in the output window:
GetGFormEntryKeys() - $entry_keys::Array
(
[username] => 4
[firstname] => 1.3
[lastname] => 1.6
[email] => 2
[Site Name] => 3
[Phone] => 19
)
This log message shows the code was able to dynamically match the numeric keys with the friendly name.
2. To verify your code retrieved posted content without prior knowledge of the field id's, locate the following logs near the bottom of the output window:
prepare_for_heap() - $leaddata::Array
(
[create] => lead
[name] => Bobby Boucher
[phone] => 555-555-5555
[email] => bobby@ilovedafootball.com
)
Test key: Site Name::waterboy_movie
Test key: Phone::555-555-5555
This log message shows the values were able to be retrieved from $entry without knowing the numeric keys ahead of time. All you need to know are the User Meta Setting names.
If there are any errors or if data isn't being loaded, review the default array values in BuildMockEntryArray() and verify $form_id matches the current GForm form_id.
** Where Can We Go From Here **
I plan on converting this into a mapping plugin that will also attempt to map input id's to the [Admin Label] Setting in the Advanced Tab of each field on a form. This should be fairly easy and only require changing the function GetGFormEntryKeys() so it loads the GForm settings for the specified form_id.
Another option would be to create a dedicated mapping page for developers to use specifically for this purpose. I could then create a class that extend the $entry array and provides the named keys for server side data mapping.
** Thoughts from GF Team **
Whew... that was a lot to present. Perhaps the GravityForms team can confirm if there is a more native way to do this via the current code base. At the very least, I've learned a lot about how GForm is setup and works.
Thanks,
David Carroll