multipage_form_set_element_visibility
- Versions
- 4.7 – 6
multipage_form_set_element_visibility(&$element, $visible, $next_page = TRUE)
Set an element's visibility. Elements are gnerally changed to hidden elements. Visibility may be set and reset any number of times.
Parameters
$element The form element array to modify.
$visible The desired visibity of the form element.
$next_page Boolean value, TRUE if the next page is about to be rendered, FALSE otherwise.
Code
developer/examples/multipage_form_example.module, line 371
<?php
function multipage_form_set_element_visibility(&$element, $visible, $next_page = TRUE) {
multipage_form_restore_attributes($element);
if (!$visible) {
switch ($element['#type']) {
case 'textfield':
case 'textarea':
case 'select':
multipage_form_set_attribute($element, '#type', 'hidden');
multipage_form_set_attribute($element, '#required', FALSE);
break;
case 'radios':
// Radios elements cannot be hidden unless they have been processed.
if ($next_page) {
multipage_form_set_attribute($element, '#type', 'hidden');
multipage_form_set_attribute($element, '#required', FALSE);
}
break;
case 'radio':
case 'checkbox':
// We can't change these to hidden until right before the next page is rendered, otherwise
// the value is lost sometimes.
if ($next_page) {
multipage_form_set_attribute($element, '#type', 'hidden');
}
break;
case 'fieldset':
multipage_form_set_attribute($element, '#type', NULL);
break;
case 'button':
if ($next_page) {
multipage_form_set_attribute($element, '#type', 'value');
}
break;
case 'submit':
if ($next_page) {
multipage_form_set_attribute($element, '#type', 'button');
}
break;
}
}
foreach (element_children($element) as $key) {
multipage_form_set_element_visibility($element[$key], $visible, $next_page);
}
}
?>Login or register to post comments 