enjoylife
enjoylife

Reputation: 5469

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.

Upvotes: 0

Views: 239

Answers (3)

easel
easel

Reputation: 4048

If the submitted form contains a variable named "search_box_form_submit", delete it, and then add a new variable called "mymodule_search_box_submit".

Perhaps somebody wanted to override the drupal search function and didn't want the default processor to fire at all. Thanks kiamlaluno in the comments.

Upvotes: 2

user557846
user557846

Reputation:

is the text "search_box_form_submit" in the array $form['#submit']
if so find the key for search_box_form_submit
then remove from array

put the value mymodule_search_box_submit in the front of the array $form['#submit']

i recommend reading the manual page for the functions used.

Upvotes: 1

prodigitalson
prodigitalson

Reputation: 60413

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'

Upvotes: 1

Related Questions