Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

gravity form, displaying fields dynamically populated WordPress


I use Gravity Form 1.8.7 and Gravity Forms PDF Extended.

I need to populate a dropdown dynamically, with the content of a (duplicatable) custom field
I use magic fields 2 to create duplicatables fields and groups.

To populate my dropdown I read this documentation : [[LINK href=""]][[/LINK]]

I write and uses this function :

add_filter('gform_pre_render_1', 'champ_horaires');

function champ_horaires($form){

foreach($form['fields'] as &$field){

if($field['type'] != 'select' || strpos($field['cssClass'], 'horaires_automatic') === false)

$choices = array(array('text' => 'Choisissez le cours qui vous interesse', 'value' => ' '));

$lieux_horaires = get_group('lieu_et_horaire');
if($lieux_horaires) {
foreach($lieux_horaires as $lieu_horaire){
$id_lieu = $lieu_horaire['lieu_et_horaire_lieu_du_cours'][1]?$lieu_horaire['lieu_et_horaire_lieu_du_cours'][1] : '';
$zipcode = get('coordonnees_code_postal',1,1,$id_lieu) ? get('coordonnees_code_postal',1,1,$id_lieu) : '';

$choices[] = array('text' => $zipcode, 'value' => $zipcode);

$field['choices'] = $choices;


return $form;

Is it possible to customize the values of this dropdown inthe backoffice ? And how ?

Thanks !

Answers (1)


Kyle answers:

PDF extend usually displays the entire Entry Object so it should display it automatically. If not, can you post the template you are using with PDF extend, as well as the configuration.php file

When you use pre_render for a dropdown like that you overwrite what the field value is, so it would pull whatever values you have for the field you are getting from magic fields - edit that and you edit the dropdown - does that make sense?

Sébastien | French WordpressDesigner comments:

this is my pdf template :

* If the template is being loaded directy we'll call the Wordpress Core
* Used when attempting to debug the template

* Set up the form ID and lead ID, as well as we want page breaks displayed.
* Form ID and Lead ID can be set by passing it to the URL - ?fid=1&lid=10

* Load the form data, including the custom style sheet which looks in the plugin's theme folder before defaulting back to the plugin's file.
$form = RGFormsModel::get_form_meta($form_id);
$stylesheet_location = (file_exists(PDF_TEMPLATE_LOCATION.'template.css')) ? PDF_TEMPLATE_URL_LOCATION.'template.css' : PDF_PLUGIN_URL .'styles/template.css' ;


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" xml:lang="en" lang="en">

<link rel='stylesheet' href='<?php echo $stylesheet_location; ?>' type='text/css' />
<title>Gravity Forms PDF Extended</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


foreach($lead_ids as $lead_id) {

$lead = RGFormsModel::get_lead($lead_id);
do_action("gform_print_entry_header", $form, $lead);
$form_data = GFPDFEntryDetail::lead_detail_grid_array($form, $lead);
* Add &data=1 when viewing the PDF via the admin area to view the $form_data array


$nom = $form_data['field']['votre nom'];
$prenom = $form_data['field']['votre prénom'];
$adresse = $form_data['field']['votre adresse'];
$ville = $form_data['field']['votre ville'];
$codepostal = $form_data['field']['votre code postal'];
$telephone = $form_data['field']['votre numéro de téléphone'];
$email = $form_data['field']['votre adresse email'];
$horaires = $form_data['field']['Horaires'];
$horairesname = $form_data['field']['Horaires_name'];
<td class="maj">nom</td>
<td><?php echo $nom; ?></td>
<td class="maj">prénom</td>
<td><?php echo $prenom; ?></td>
<td class="maj">adresse</td>
<td><?php echo $adresse; ?></td>
<td class="maj">ville</td>
<td><?php echo $ville; ?></td>
<td class="maj">code postal</td>
<td><?php echo $codepostal; ?></td>
<td class="maj">téléphone</td>
<td><?php echo $telephone; ?></td>
<td class="maj">email</td>
<td><?php echo $email; ?></td>
<td class="maj">horaires</td>
<td><?php echo $horaires; ?></td>
<td class="maj">horaires name</td>
<td><?php echo $horairesname; ?></td>




That works perfectly.
But i don't know how to display the value of my dropdown programatically populated.

Kyle comments:

You should be able to pull the dropdown submission the same as any other field. Here you are using the field title, which is case sensitive etc. Did you try just by doing the field ID? It would be less sensitive.

Also, you may want to try to print out the entire entry object in the pdf just to make sure that the data is being passed.

Sébastien | French WordpressDesigner comments:

Ok... the first problem wasn't a problem in fact...
I explain : the value returned wa like "75001" or "75006", but I wait something like "75008 | The Eiffel Tower"...

but in fact the pipe | seems the problem ! If i remove it, i have no more problem.

But i have already this question : Is it possible to customize the values of this dropdown inthe backoffice ? And how ?

Kyle comments:

Are you trying to change it manually or with pre_render in the backend?

Kyle comments:

If you want to see what the pre_render dropdown looks like in the backend, you can use admin_pre_render

[[LINK href=""]][[/LINK]]

But you can't really edit it in the backend, you can just preview it. The pre_render hook will still control all the values. Only by editing your second $zipcode var in your pre_render, can you change the values.

Sébastien | French WordpressDesigner comments:

thx, the problem is resolved :)