Gravity Forms. I try to manipulate the form fields before they are rendered with

add_filter("gform_pre_render", "my_function", 10, 5);

function my_function($form){
$form["fields"][0]["content"] = 'This is a html-block'

Like this, I can pass the html-block's content assumed the html is the first field on the form. How can I target a field by id? Let's say the above html-block-field has the field id 13.


According to this page about the form fields object, it looks like you'd need to do something like this:

$my_id = '37';
foreach($form['fields'] as $field){
    if($field['id'] == $my_id){
        $field['content'] = 'This is a html-block';

where $my_id is the id of the field you are targeting

| improve this answer | |
  • If $form["fields"]["37"]["content"] does not work, your answer GhostToast will not work either, or am I wrong? – wamps Aug 19 '13 at 18:30
  • No. Because 'id' is a real field. The way you mention ["37"] indicates no assignment to a key. This is not a simple array. – GhostToast Aug 19 '13 at 18:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.