Last active
December 17, 2015 15:40
-
-
Save berdyshev/5633761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Add/Edit Form | |
*/ | |
function MYMOD_formid_form($form, $form_state){ | |
$form['event'] = array( | |
'#title' => t('Event'), | |
'#type' => 'select', | |
'#empty_option' => '', | |
'#options' => $event_options, // доступные варианты | |
'#ajax' => array( | |
'event' => 'change', | |
'wrapper' => 'event-sets-wrapper', // id тега-wrapper'а | |
// callback, возвращающий новый кусочек формы | |
'callback' => '_MYMOD_ajax_subscription__eventsets', | |
'method' => 'replaceWith', // заменить содержимое враппера | |
'effect' => 'slide', // красотульки | |
), | |
'#default_value' => $subscription->event, | |
); | |
$form['event_sets'] = array( | |
// Wrapper, в котором будет заменяться зависимая часть формы | |
'#type' => 'container', | |
'#tree' => TRUE, | |
'#attributes' => array('id' => 'event-sets-wrapper'), | |
); | |
// Здесь рисуем зависимую часть формы | |
if (isset($form_state['values']['event'])) | |
switch ($form_state['values']['event']){ | |
case 'first': | |
$form['event_sets'] += MYMOD_attach_first_part_form($form, $form_state); | |
break; | |
} | |
} | |
/** AJAX callback for the 'event' field | |
*/ | |
function _MYMOD_ajax_subscription__eventsets($form, $form_state){ | |
return $form['event_sets']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment