1

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.

closed as off-topic by Pieter Goosen, Nicolai, birgire, Johannes Pille, gmazzap Sep 2 '14 at 8:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Pieter Goosen, Nicolai, birgire, Johannes Pille, gmazzap
If this question can be reworded to fit the rules in the help center, please edit the question.

1

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

  • 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.