-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiple_submit_buttons.module
56 lines (50 loc) · 1.73 KB
/
multiple_submit_buttons.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
// Implements hook_menu()
function multiple_submit_buttons_menu() {
$items['demo/multiple_submit_buttons/form'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_submit_buttons_customform_form'),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function multiple_submit_buttons_customform_form($form, $form_state) {
$form = array(
'name' => array(
'#type' => 'textfield',
'#title' => 'Enter your name',
'#maxlength' => '128',
),
'actions' => array(
'forward' => array(
'#type' => 'submit',
'#value' => 'Forwards',
),
'backward' => array(
'#type' => 'submit',
'#value' => 'Backwards',
),
),
);
return $form;
}
function multiple_submit_buttons_customform_form_validate($form, &$form_state) {
if ($form_state['values']['op'] == 'Forwards') {
drupal_set_message('This validation only runs when you click the forward button.');
} elseif ($form_state['values']['op'] == 'Backwards') {
drupal_set_message('This validation only runs when you click the backwards button.');
} else {
drupal_set_message('Unknown Action chosen');
}
return TRUE;
}
function multiple_submit_buttons_customform_form_submit($form, &$form_state) {
if ($form_state['values']['op'] == 'Forwards') {
drupal_set_message('This is your string forwards: ' . $form_state['values']['name']);
} elseif ($form_state['values']['op'] == 'Backwards') {
drupal_set_message('You chose to print your input out backwards: ' . strrev($form_state['values']['name']));
} else {
drupal_set_message('We aren\'t sure what you wanted to do, but your input is: ' . $form_state['values']['name']);
}
}