I’ve written a lot of PHP code but I’m new to manipulating Gravity Forms via PHP. I have a long form where I need to do quite a few things to particular fields, both when the form is loaded and when it’s submitted. One simple example is setting the default for a given field when the form is loaded. I’ve worked out that I can do the following:
//$year is established by earlier code based on various parameters.
foreach( $form[‘fields’] as &$field ) {
if($field->id == 6) {
$field->defaultValue = $year;
}
}
Is there a way to simplify this to single line, something that directly targets the field in question rather than looping through all the fields? Thanks!