1

I am building a site with several forms that partly contain identical building blocks (for example a fieldset 'payment details'). Ideally, I would like to design my form elements separately and then inject them into each form. My idea was to create functions with &$form as parameter, as in the following code:

function payment_details(&$form) {  
  $form['payment_details']['amount'] = array(  
    '#title' => t('Payment Amount'),  
    '#type' => 'textfield',  
  );  
}

I then call the function in my form definition.

transaction_form() {  
  // ...  
  payment_details(&$form);  
  // ...  
  return $form;  
}  

While the approach leads to the desired result, Drupal gives me the following warning:

Deprecated function: Call-time pass-by-reference has been deprecated in drupal_load() (line 1100 of C:\Wamp\www\paradise\includes\bootstrap.inc).

Maybe anyone can give me a better way to reach my goal? At least, can you guys advise on how to fix this problem? I understand from various forum posts that this is a PHP related issue, and that it can be more or less ignored for development. Do you agree?

1 Answer 1

2

Your function already accepts the $form variable by reference (function payment_details(&$form)) so you don't have to pass the $form element by reference when calling that function. Just use payment_details($form); in your form builder and you should be fine. Passing by reference is deprecated in recent PHP versions, so that's why you get a warning.

0

Your Answer

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

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