Can not create a table - Drupal 7 - drupal

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,
);
?>

Related

Wordpress / CMB2 Framework / Display data from repeatable fields in frontend

I have a own option-page in the backend-sidebar with this repeatable fields in it. (not a metabox) I cant figure out, how to display the data from the group field in the frontend.
function ww_register_theme_options() {
$ww_prefix = '_ww_';
$ww_contacts = new_cmb2_box( array(
'id' => $ww_prefix . 'ww_option_plugin',
'title' => esc_html__( 'Ansprechpartner', 'ww-contact' ),
'icon_url' => '/wp-content/plugins/ww-contact/assets/images/icons/ww-icon-white.png',
'object_types' => array( 'options-page' ),
'option_key' => 'ww_options',
) );
$ww_group_field = $ww_contacts->add_field(array(
'id' => $ww_prefix . 'contact_repeat_group',
'type' => 'group',
'description' => __('Ansprechparter Liste', 'ww-contact'),
'repeatable' => true,
'options' => array(
'group_title' => 'Ansprechpartner {#}',
'add_button' => __('neuer Ansprechpartner', 'ww-contact'),
'remove_button' => __('Entfernen', 'ww-contact'),
'sortable' => true,
),
));
$ww_contacts->add_group_field($ww_group_field, array(
'name' => 'Vorname',
'id' => $ww_prefix . 'forname',
'type' => 'text',
));
$ww_contacts->add_group_field($ww_group_field, array(
'name' => 'Vorname',
'id' => $ww_prefix . 'surname',
'type' => 'text',
));
}
Remove the prefix from your add_group_field ids they aren't needed. Then loop through like so...
$entries = get_post_meta( $parent, 'ww_contact_repeat_group', true );
if($entries){
foreach ( (array) $entries as $key => $entry ) {
if ( isset( $entry['forname'] ) ) {
$forname = $entry['forname'];
}
}
}

Drupal #states how to make it work

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 ?

Unable to add custom select field in woocommerce

I want to add a custom field options to checkout page. I am using the following code :
$fields['billing']['billing_options'] = array(
'label' => __('Options', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => false,
'clear' => false,
'type' => 'select',
'options' => array(
'option_a' => __('option a', 'woocommerce' ),
'option_b' => __('option b', 'woocommerce' )
)
);
I want to show the options (option_a,option_b) from database or
I want to use dynamic data and want to use for loop in the options menu
How can I use for loop inside this function ?
Just do it before, like this:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function my_custom_checkout_fields( $fields ) {
$args = array(
'post_type' => array('options'),
'posts_per_page' => -1
);
$posts = new WP_Query($args);
$options = array();
foreach ($posts as $post) {
$options[$post->ID] => attr_esc($post->post_title);
}
$fields['billing']['billing_options'] = array(
'label' => __('Options', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => false,
'clear' => false,
'type' => 'select',
'options' => $options
);
return $fields;
}

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"];
}

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

Resources