Viewed   110 times

I ran across some example code that looks like this:

$form['#submit'][] = 'annotate_admin_settings_submit';

Why is there a bracket after ['#submit'] that is empty with nothing inside? What does this imply? Can anyone give me an example? Normally (from my understanding which is probably wrong) is that arrays have keys and in this case the the $form array key '#submit' is equal to 'annotate_admin_settings_submit' but what is the deal with the second set of brackets. I've seen examples where an array might look like:

$form['actions']['#type'] = 'actions';

I know this is a very basic question about php in general but I ran across this question while learning Drupal so hopefully someone in the Drupal community can clarify this question that I'm obsessing over.



When you say $form['actions']['#type'] = 'actions', it assigns a value to $form['actions']['#type'], but when you say $form['#submit'][] = 'annotate_admin_settings_submit', if $form['#submit'] is an array, it appends 'annotate_admin_settings_submit' to the end of it, and if it's empty, it will be an array with one single element that is 'annotate_admin_settings_submit'.

Saturday, October 22, 2022

Use array_filter to iterate over each value. If you don't provide a callback, any key whose value == false gets removed. Empty is close enough to false for PHP.

echo count(array_filter($auflistung));

ZombieHunter has a good point about creating the array from non-empty values. This is a clean way of doing that.


foreach ($keys as $key){
    if (isset($_POST[$key]) && !empty($_POST[$key])) $auflistung[]=$_POST[$key];

echo count($auflistung);
Sunday, October 9, 2022

So there is sneaky way to alter the location field, what you need to do is to use the #after_built callback:

 * Implements hook_form_alter().                                     
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'x_node_form') {
    // alter the location field
    if (isset($form['locations'])) {
      $form['locations']['#after_build'][] = 'mymodule_alter_location_field';

 * Remove the delete checkbox from location element.
function mymodule_alter_location_field($form_element, &$form_state) {
  $location = $form_element[0]; // The location field which you can alter
  return $form_element;
Monday, October 31, 2022

For a prod environment, display_errors is set off in PHP runtime on Azure Web Apps. We can open the setting for debugging via change the build-in PHP configurations.

Here are simple steps:

1, Add a .user.ini file to your root directory.

2, Add configuration settings to the .user.ini file using the same syntax you would use in a php.ini file. With your demand, your .user.ini file would contain this text:

display_errors = On

3, Deploy your web app.

4, Restart the web app.

You can read official guide for more information.

Furthermore, we can login in the Kudu console of our websites to manage our sites. The URL of Kudu console should be like: https://{your_web_site_name}., and click Tools => Diagnostic dump to download the diagnostic logs.

Additional, we can use WebMatrix to directly modify your code on Azure Web Apps.

Sunday, August 14, 2022

Use array_values($arr). That will return a regular array of all the values (indexed numerically).

PHP docs for array_values

Tuesday, December 6, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :