0

I'm using #after_build in one of my custom module form like follows

  $form['profile_image'] = array (
    '#type' => 'managed_file',
     '#after_build' => array("change_pic"),
  );

and the function is

function change_pic($element, &$form_state, $form) {
  if($form_state['values']['profile_image']['fid'] != 0){
    // my code goes here..
    return $element;
  }
}

It's working fine in PHP 5x version. but throws the following error in PHP 7x version.

ArgumentCountError: Too few arguments to function change_pic(), 2 passed How can we handle this in PHP 7?

Any inputs would be helpful.

2 Answers 2

1

There are only 2 args to an after build method, the element and the form state.

Just remove the extra one and it’ll work:

function change_pic($element, &$form_state)
0
0

Clive's answer to use only those 2 arguments is correct; but this is also wrong on your code:

 $form['profile_image'] = array (
    '#type' => 'managed_file',
     '#after_build' => array("change_pic"),
  );

this will wipe out any other after builds added by other modules. You should add like this:

 $form['profile_image']['#after_build'][] = 'change_pic';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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