Drupal #states how to make it work - drupal

I'm trying to make #states work on drupal, I have a select field like this :
$form['options'][$default_set_id]['none']['order_fields'][$field_name] = array(
'#type' => $widget_types[$order_field['widget']['type']],
'#suffix' => '<div class="field-description">' . $order_field['description'] . '</div>',
'#title' => $order_field['label'],
'#default_value' => '',
'#options' => field_info_field($field_name)['settings']['allowed_values']
);
and my field that need the #states :
$form['options'][$default_set_id]['none']['order_fields'][$field_name] = array(
'#type' => $widget_types[$order_field['widget']['type']],
'#suffix' => '<div class="field-description">' . $order_field['description'] . '</div>',
'#title' => $order_field['label'],
'#default_value' => isset($current_options['order_fields'][$field_name]) ? $current_options['order_fields'][$field_name] : '',
'#states' => array(
'visible' => array(
':select[name="field_transport_rdv"]' => array('value' => 'autre'),
)
)
);
I'm doing all like in the documentation and examples I found in internet, but it seems not work, anyone have an idea ?

Related

Get value from option tree wordpress

I want to be use some sliders in my wordpress theme. I want to select them in my theme option. I am using the code below.
<?php
$slider_select = get_option_tree( 'slider_select', '', 'true' );
?>
<?php get_template_part('$slider_select'); ?>
But, it is not working. I want the get_template_part code worked. Any suggestion?
replace
get_template_part('$slider_select');
with
get_template_part($slider_select);
You can use this method for create a slider in option tree.
create settings array like this.
array(
'id' => 'my_slider',
'label' => 'Images',
'desc' => '',
'std' => '',
'type' => 'list-item',
'section' => 'general',
'class' => '',
'choices' => array(),
'settings' => array(
array(
'id' => 'slider_image',
'label' => 'Image',
'desc' => '',
'std' => '',
'type' => 'upload',
'class' => '',
'choices' => array()
),
array(
'id' => 'slider_link',
'label' => 'Link to Post',
'desc' => 'Enter the posts url.',
'std' => '',
'type' => 'text',
'class' => '',
'choices' => array()
),
array(
'id' => 'slider_description',
'label' => 'Description',
'desc' => 'This text is used to add fancy captions in the slider.',
'std' => '',
'type' => 'textarea',
'class' => '',
'choices' => array()
)
)
)
Add into page using loop
$my_slider = ot_get_option( 'my_slider' );
foreach($my_slider as $slider){
echo '<img src="'.$slider["slider_image"].'">';
echo $slider["slider_link"];
echo $slider["slider_description"];
}

Can not create a table - Drupal 7

I am trying to create a table inside one of my forms, but I am having some errors (Notice : Undefined offset: X in theme_tableselect() ) and the content of my table is then wrong.
This is my code if someone could tell me what I miss :
<?php
$headers = array(
t('Nom'),
t('Description'),
t('Nombre vidéos'),
t('Durée'),
t('Mode de lecture'),
t('Date'),
t('Actions'),
);
$form["gestionvideos_array"] = array(
'#type' => 'fieldset',
'#title' => t('Playlists'),
'#description' => t('Something'),
);
foreach( $aPlaylist as $oPlaylist ){
$rows = array(
'Nom' => ucfirst($oPlaylist->sPlaylistName),
'Description' => $oPlaylist->sDescription,
'Nombre vidéos' => $oPlaylist->iTotal,
'Durée' => $oPlaylist->sDuree,
'Mode de lecture' => $oPlaylist->sMode,
'Date' => $oPlaylist->dCreated,
'Actions' => $oPlaylist->sAction,
);
}
$form["gestionvideos_array"]["table"] = array(
'#type' => 'tableselect',
'#header' => $headers,
'#options' => $rows,
);
?>

Trying to add 'group of fields' with 'add more' in drupal in a custom module form

I have been trying writing a custom module in drupal 7 with a form to have a group of fields with 'add more' option as in 'Field Collection'(don't want to use module but write the code for control). I tried to find a good example but no success. Can anybody suggest how to proceed? Plz!!
Thanks in advance.
$form['education']['languages'] = array(
'#type' => 'fieldset',
'#title' => t('Languages'),
'#prefix' => '<div id="div_languages-fieldset-wrapper">',
'#suffix' => '</div>',
);
for ($i = 0; $i < $form_state['language_num']; $i++)
{
$form['education']['languages'][$i]['labels'] = array(
'#prefix' => '<h1 id = "stu_form_label">',
'#type' => 'item',
'#title' => t('Form :'.($i+1)),
'#suffix' => '</h1>',
);
// Language Drop down box
$option_language = _get_language_mstr();
$form['education']['languages'][$i]['language'] = array(
'#prefix' => '<div class="container-inline bottom_space languages_drop_down">',
'#options' => $option_language,
'#type' => 'select',
'#title' => t('Language'),
'#suffix' => '</div>',
);
// Level Drop down box
$option_Level = _get_level_mstr();
$form['education']['languages'][$i]['level'] = array(
'#prefix' => '<div class="container-inline bottom_space languages_drop_down">',
'#options' => $option_Level,
'#type' => 'select',
'#title' => t('Level'),
'#suffix' => '</div>',
);
}
if ($form_state['language_num'] > 1)
{
$form['education']['languages']['remove_name'] = array(
'#type' => 'submit',
'#value' => t('Remove last language'),
'#limit_validation_errors' => array(),
'#submit' => array('remove_one_language'),
'#ajax' => array(
'callback' => 'add_more_callback_language',
'wrapper' => 'div_languages-fieldset-wrapper',
),
);
}
$form['education']['languages']['add_name'] = array(
'#type' => 'submit',
'#value' => t('Add language'),
'#limit_validation_errors' => array(),
'#submit' => array('add_one_language'),
'#ajax' => array(
'callback' => 'add_more_callback_language',
'wrapper' => 'div_languages-fieldset-wrapper',
),
);
function add_more_callback_language($form, $form_state) {
return $form['education']['languages'];
}`
Try this method
Sample Link: URL
Click the tab education

submit button appears only after selection from the dropdown list doesn't work - drupal 7

Submit button appears after selecting from the select list drop down ,
Can anyone help me understand why it is not working?
$form['user_fields']['optinal_packages'] = array(
'#type' => 'select',
'#title' => t('Optional Packages'),
'#options' => $packages_array,
//'#weight' => 15,
'#description' => t('Please press the "Push" button to update device package.'),
'#default_value' => -1,
);
$form['user_fields']['push'] = array(
'#type' => 'submit',
'#value' => t('Push'),
// '#weight' => 16,
'#prefix' => '<div id="phone_user_push_package">',
'#suffix' => '</div>',
'#states' => array(
'visible' => array( // Action to take: Make visible.
//':input[name="optinal_packages"]' => array('!value' => '-1'),
'select[name="optinal_packages"]' => array('!value' => '-1'),
),
),
);
Thanks
dana
Change the code to be
$form['user_fields']['push'] = array(
'#type' => 'submit',
'#value' => t('Push'),
// '#weight' => 16,
'#prefix' => '<div id="phone_user_push_package">',
'#suffix' => '</div>',
'#states' => array(
'invisible' => array( // edited line
':select[name="optinal_packages"]' => array('value' => '-1'), // edited line
),
),
);
Change select[name="optinal_packages"] to be :select[name="optinal_packages"]. If it doesn't work, try to change the selector to be CSS-like #edit-optinal-packages.
Hence the code will be:
'#edit-optinal-packages' => array('value' => '-1'),

jquery accordion drupal 6 id problem

I am using jquery accordion (v.1.8). When I use prefix for div creation id is missing i.e.
$form['container'] = array(
'#prefix' => '<div>',
'#attributes' => array('id' => 'accordion'),
'#suffix' => '</div>'
);
I cant see any id = "accordion" in DOM
plus if I use this method below:
$form['container'] = array(
'#prefix' => '<div id = "accordion">',
'#value' => t('&nbps;'),
'#suffix' => '</div>'
);
it works can you please tell me the reason since am new to drupal
That's because Drupal is looking for some form element to add the id to but none are found. For instance, if you make #type a fieldset as in below, the fieldset will have an id of "accordian".
$form['container'] = array(
'#type' => 'fieldset',
'#prefix' => '<div>',
'#attributes' => array('id' => 'accordion'),
'#suffix' => '</div>',
);
The code above will output a DIV that contains a fieldset with an id of "accordian". From there you could add other form elements inside the fieldset, like:
$form['container']['fake'] = array(
'#type' => 'textfield',
'#title' => t('My Textfield'),
'#size' => 30,
'#maxlength' => 128,
'#required' => TRUE,
);
For more information about Drupal forms, see the Forms API Reference, it is an extremely valuable source information.

Resources