Search code examples
phpformsdrupaldrupal-6

What does this code do?


if (in_array($form['#submit'], 'search_box_form_submit')) {
    $key = array_search('search_box_form_submit', $form['#submit']);
    unset($form['#submit'][$key]);
}

array_unshift($form['#submit'], 'mymodule_search_box_submit');

What does the code do? I don't follow it well; I expect someone can explain it to me, line by line.


Solution

  • if (in_array($form['#submit'], 'search_box_form_submit')) {

    If the value 'search_box_form_submit' is present in the array $form['#submit']

    $key = array_search('search_box_form_submit', $form['#submit']);

    Then set the variable $key to the array key for the value 'search_box_form_submit' in the array $form['#submit']

    unset($form['#submit'][$key]);

    Then unset (delete) that array element

    array_unshift($form['#submit'], 'mymodule_search_box_submit');

    Put a new element at the beginning of the array $form['#submit'] with the value 'mymodule_search_box_submit'