Jump to content

Recommended Posts

I am trying to retrieve data from a gravity form and wish to extract the data into variables that I can then use.

I have got the values in an array but can't figure out how to put them into variables.

 

This is my code

<?php 
    $lead_id = 3;
    $lead = RGFormsModel::get_lead( $lead_id ); 
    $form = GFFormsModel::get_form_meta( $lead['form_id'] ); 
 
    $values= array();
 
    foreach( $form['fields'] as $field ) {
         var_dump($fields);
        $values[$field['id']] = array(
            'id'    => $field['id'],
            'label' => $field['label'],
            'value' => $lead[ $field['id'] ],
            
        );
    }
    
?>
Link to comment
https://forums.phpfreaks.com/topic/283893-help-with-array/
Share on other sites

Hi,

I want to put the field values into variables e.g.$property_title=?

I used print r to view the values but I don't know how to get the value from the array.

The array is

Array
(
[1] => Array
(
[id] => 1
[label] => Property Title
[value] => A New Property 2
)

[2] => Array
(
[id] => 2
[label] => Estate Agent
[value] => Me
)

[3] => Array
(
[id] => 3
[label] => Property Reference
[value] => 1123
)

[4] => Array
(
[id] => 4
[label] => Brief Description
[value] => Brief description
)

[6] => Array
(
[id] => 6
[label] => Add Brochure
[value] => http://localhost/wordpress/site2/files/gravity_forms/2-bb2623c01495bb311c734b2c44390d23/2013/10/Drovers-Way-Bude-Cornwall.pdf
)

[7] => Array
(
[id] => 7
[label] => Post Code
[value] => EX23 9DZ
)

)

Link to comment
https://forums.phpfreaks.com/topic/283893-help-with-array/#findComment-1458243
Share on other sites

I wouldn't assign each field to a seperate variable. Instead I make the field label the key.

$fields = array();
 
foreach( $form['fields'] as $field ) {
    
    // make field label the key
    $key = str_replace(' ', '_', strtolower($field['label']));
    $fields[ $key ] = array(
        'id'    => $field['id'],
        'label' => $field['label'],
        'value' => $lead[ $field['id'] ],
    );
}

So to access the Estate Agent field value you'd can do $fields['estate_agent']['value'].

 

Note: I renamed the $values array to $fields

Edited by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/283893-help-with-array/#findComment-1458244
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.