0

Here is a small PHP code which I am not clear with.

/**
* Form for configurable Drupal action to beep multiple times
*/
function beep_multiple_beep_action_form($context) {
$form['beeps'] = array(
'#type' => 'textfield',
'#title' => t('Number of beeps'),
'#description' => t('Enter the number of times to beep when this action executes'),
'#default_value' => isset($context['beeps']) ? $context['beeps'] : '1',
'#required' => TRUE,
);
return $form;
}

In the above user defined function return $form what does it return? How do you access the individual elements of $form what is the significance of writing beeps in square braces in $form

function beep_multiple_beep_action_validate($form, $form_state) {
        $beeps = $form_state['values']['beeps'];
        if (!is_int($beeps)) {
        form_set_error('beeps', t('Please enter a whole number between 0 and 10.'));
        }
        else if ((int) $beeps > 10 ) {
        form_set_error('beeps', t('That would be too annoying. Please choose fewer than 10
        beeps.'));
        } else if ((int) $beeps < 0) {
        form_set_error('beeps', t('That would likely create a black hole! Beeps must be a
        positive integer.'));
        }
}

In above code what is

$beeps = $form_state['values']['beeps'];

line doing?

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by cereal
0

beep_multiple_beep_action_form() is a function to build an array, you can use print_r to display the array:

$a = beep_multiple_beep_action_form($context);
print_r($a);

But you need to search where this function is used, in order to see the original array.
This code $beeps = $form_state['values']['beeps']; instead is used to display part of a multidimensional array, something like this:

array(
    'values' => array('beeps' => 'some data')
);

bye.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.