Hello everybody and thanks for reading.
I have this
<?php
echo $form->textField($model, 'link', array(
'prepend' => '<i class="icon-4x icon-globe" style="line-height: 54px;"></i>',
'class' => 'span12', 'maxlength' => 999,
'height'=>100,
'htmlOptions' => array('style' => 'height:60px;font-size: 22px;')
));
?>
This is not working for width but when i replace it with height its not working. There is no other css rules that overwrite it .
How can i set a custom height on a textfiled in yii
from yii docs:
public string textField(CModel $model, string $attribute, array $htmlOptions=array ( ))
so you should have:
$form->textfield($model,'link',array('style'=>'width:600px;'));
i see that you also have a class:
$form->textfield($model,'link',array('style'=>'width:600px;', 'class' => 'class_x'));
now, let me explin what happens within your code:
echo $form->textField($model, 'link', array(
'prepend' => '<i class="icon-4x icon-globe" style="line-height: 54px;"></i>',
'class' => 'span12', 'maxlength' => 999,
'height'=>100,
'htmlOptions' => array('style' => 'height:60px;font-size: 22px;')
));
the first and second parameters are ok
when it comes to the 3rd one, at first it looks fine, because it is a array, that represents the htmlOptions array from the documentation
if you digg deeper, you see that in the htmlOptions array you have another htmlOptions array; WHY?
write like this:
echo $form->textField($model, 'link', array(
'prepend' => '<i class="icon-4x icon-globe" style="line-height: 54px;"></i>',
'class' => 'span12',
'style' => 'height:60px;font-size: 22px;width:999px;',
));
You can use something like:
echo $form->textField($model,'link',array('size'=>50,'maxlength'=>50,));
Related
I'm using redux framework in my theme and I'm customizing my theme by extending the WP_Customize_Section using the file "customizer_section.php"
While Defining my Options, I have defined a section as:
Redux::setSection($myTheme_opt_name, array(
'id' => 'my-th-shortcode-subsec-shortcodes-blog-tab',
'title' => __('Blog', 'myTheme'),
'subsection' => true,
'class' => MyCSSClass,
'fields' => array(
array(
'subtitle' => __('Controls the color of the icon circle in blog alternate and recent posts layouts.', 'myTheme'),
'id' => 'my-th_shortcode_blog_icon_circle_color',
'compiler' => true,
'type' => 'color',
'title' => __('Blog Icon Circle Color', 'myTheme'),
'default' => '#eef0f2',
),
),
)
);
in our own customizer_section.php I want to add in the class defined in my options on my own codeblock
protected function render_fallback() {
$classes = 'accordion-section redux-section control-section control-section-' . $this->type;
?>
<li id="accordion-section-<?php echo esc_attr($this->id); ?>" class="<?php echo esc_attr($classes); ?>">
<h3 class="accordion-section-title" tabindex="0">
<?php
echo wp_kses($this->title, array(
'em' => array(),
'i' => array(),
'strong' => array(),
'span' => array(
'class' => array(),
'style' => array(),
),
));
?>
</h3>
in the above code in the li tag I want to get the css class (MyCSSClass) which I have defined in my options above. How can I get that css class in here?
ok Figured it out..... I used the code below to get the class of a section and used it in the li class
$this->class_name = isset($this->section['class']) ? $this->section['class'] : '';
I have 7 pages about services.
In documentation of Redux Framework explain the class select and multi select
Example Multi Select code:
$fields = array(
'id' => 'opt-multi-select',
'type' => 'select',
'multi' => true,
'title' => __('Multi Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
//Must provide key => value pairs for radio options
'options' => array(
'1' => 'Opt 1',
'2' => 'Opt 2',
'3' => 'Opt 3'),
'default' => array('2','3')
);
How I do for in options insert dynamically all pages ids or posts ids registered in DB?
UPDATED
Redux::setSection($opt_name, array(
'id' => 'options_services',
'title' => 'Services',
'subsection' => true,
'fields' => array(
array(
'id' => 'opt-multi-select_pages',
'type' => 'select',
'multi' => true,
'title' => 'Multi Select Option',
'data' => 'pages', // select pages
'args' => array( 'posts_per_page' => -1 ),
'default' => array('1','2','3','4','5')
)
)
));
index.php
<?php
foreach ($global_master['options_services'] as $singleValue){
?>
<div class="col-md-6 col-sm-6">
<div class="service-item">
<h4> <strong><?php echo $singleValue['post_title'] ?> </strong></h4>
<img src="<?php echo $singleValue['post_thumbnail_url'] ?>" alt="..." class="img-thumbnail img-responsive">
See More
</div>
</div>
<?php
}
?>
The above code does not return anything in the index
In the code I Try use returns 'post_title' and 'guid' indicated in documentation wordpress and not have references of 'post_thumbnail_url.'
UPDATED 2
I was able to solve my initial doubt with the help of Nathan Dawson and to print I used the code below:
<?php
foreach ($global_master['opt-multi-select_pages'] as $singleValue){
$post_thumbnail_id = get_post_thumbnail_id($singleValue);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
?>
<div class="col-md-6 col-sm-6">
<div class="service-item service">
<h4> <strong><?php echo get_the_title($singleValue); ?> </strong></h4>
<img src="<?php echo $post_thumbnail_url; ?>" alt="..." class="img-thumbnail img-responsive">
See more
</div>
</div>
<?php
}
?>
Fields in the Redux Framework have the option to dynamically list pages out of the box, you simply need to set the argument. Drop 'options' and set a value for 'data' instead.
Example:
$fields = array(
'id' => 'opt-multi-select',
'type' => 'select',
'multi' => true,
'title' => __('Multi Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
'data' => 'pages', // select pages
'args' => array( 'posts_per_page' => -1 ),
'default' => array('2','3')
);
You may notice I've also added the 'args' option. The pages 'data' option will retrieve 20 by default, the custom args retrieve all pages instead.
Documentation: https://docs.reduxframework.com/core/the-basics/using-data-argument/
Try this.
//$page_id_array store your all page ids
$page_id_array = get_all_page_ids();
//$options will store multi select options.
$options = array();
foreach( $page_id_array as $page_id ){
$options[$page_id] = get_the_title($page_id);
}
$fields = array(
'id' => 'opt-multi-select',
'type' => 'select',
'multi' => true,
'title' => __('Multi Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
//Must provide key => value pairs for radio options
'options' => $options,
'default' => array('2','3'),
);
I have a problem with drupal_render (assuming that drupal_render is the right way for me to get what I want - feel free to correct me =).
I am building a form. Since the FAPI does not provide a "table"-field, I want to make one myself. My approach: use the theme()-function, specifically theme('table', ...) or theme_table(), and fill it with the respective form fields (with the intention of adding AHAH functionality later on). This forces me to use drupal_render as the value for the table cells, which causes some problems with the form elements.
The table collects numbers of employees by year, for the organisation the user is editing at this moment. The code looks as follows:
$form['employees'] = array(
'#type' => 'fieldset',
'#title' => t('Employees'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$employee_query = db_query("SELECT * FROM {employees} WHERE id_organisation = %d", $org['idoOrganisation']);
$employee = array();
while ($row = db_fetch_array($employee_query)) {
$employee[] = $row;
}
$header = array(
t('Year'),
t('Total'),
t('Internal'),
t('External'),
t('Aerospace')
);
$em_delta = 0;
$rows = array();
foreach($employee as $em_delta => $value) {
$form['employees'][$em_delta]['year'] = array(
'#title' => '',
'#type' => 'date_select', // Comes with the date module
'#date_format' => $format_year,
'#date_label_position' => 'within',
'#date_year_range' => '-50:+3',
'#default_value' => $value[$em_delta]['year'],
'#id' => 'edit-employees-' . $em_delta . '-year', // Allready a quickfix, since the form is rendered without id
'#name' => 'employees['.$em_delta.'][year]', // Same here
);
$form['employees'][$em_delta]['total'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => $value['total'],,
'#size' => 1,
'#id' => 'edit-employees-' . $em_delta . '-total',
'#name' => 'employees['.$em_delta.'][total]'
);
$form['employees'][$em_delta]['internal'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => $value[$em_delta]['internal'],
'#size' => 1,
'#id' => 'edit-employees-' . $em_delta . '-internal',
'#name' => 'employees['.$em_delta.'][internal]',
);
$form['employees'][$em_delta]['external'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => $value[$em_delta]['external'],
'#size' => 1,
'#id' => 'edit-employees-' . $em_delta . '-external',
'#name' => 'employees['.$em_delta.'][external]',
);
$form['employees'][$em_delta]['aero'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => $value[$em_delta]['aero'],
'#size' => 1,
'#id' => 'edit-employees-' . $em_delta . '-aero',
'#name' => 'employees['.$em_delta.'][aero]',
);
$rows[] = array(
drupal_render($form['employees'][$em_delta]['year']),
drupal_render($form['employees'][$em_delta]['total']),
drupal_render($form['employees'][$em_delta]['internal']),
drupal_render($form['employees'][$em_delta]['external']),
drupal_render($form['employees'][$em_delta]['aero']),
);
}
$form['employees']['table'] = array (
'#value' => theme('table', $header, $rows, array(), NULL)
);
Here are the problems I am encountering:
ID- and Name-Attributes of the form elements are empty. I found something on this on the drupal site and have made my peace with it (although I don't understand it), setting those attributes manually now.
Default-values of the text fields are ignored. The fields are empty. When I let drupal_get_form render the field, the default_value shows. Someone around here suggested to set the #value-property instead, but then again I read that this is something completly different and may cause problems.
The date_select-Field is not rendered in it's entirety. The wrappers are there, the select field however appears outside of the code, just before the table (i.e. where it appears in the code).
Let's hope that's it =)
Can anybody help? What am I doing wrong?
A colleague of mine pointed out that using drupal_render within the form function is not event remotely close to being a good idea, as it removes part of the form from the whole process of validating and submitting.
Thus, figuring out why the function does not work as intended is futile. The better approach would be to simply generate the necessary amount of form fields, let them be rendered as they are within drupal_get_form(), and use the forms theme-function later on to put them into a table.
Stupid me =)
Im having a bit of a problem with my theme, i have added the following code to page.tpl.php to display the main menu links, but nothing is showing.
$main = menu_navigation_links('main-menu', '1');
echo theme('links__system_main_menu', array(
'links' => $main,
'attributes' => array(
'id' => 'nav'
),
));
Could someone let me know where im going wrong.
Cheers,
Try with this
print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu',
'class' => array('links', 'inline', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
));
Otherwise you can always place the menu throught blocks and regions.
This is because you are asking for a depth (=1) where you do not have any links.
Try $main = menu_navigation_links('main-menu', '0');
Drupal 7 API about menu_navigation_links
I wonder if anyone can help me out with this..
I have a foreach loop in a form in drupal which iterates through options for some JQuery sliders.
This works fine.
However I wanted to add a markup field within the loop, so that I could have a header div above wach slider. Instead of looping through each one, it displayed all 4 headers in one go, then all 4 sliders? Is this the correct behaviour? Please see below.
foreach ($categories as $key => $title) {
$form['sliderHead'][$key] = array(
'#type' => 'markup',
'#value' => "<div id='sliderHeaders'>Header Text</div>"
);
$form['vote'][$key] = array(
'#type' => 'slider',
'#title' => $title,
'#name' => $key, // TODO: define it with the $key variable.
'#options' => $options,
);
}
Thanks a lot,
Ross
Because Drupal renders in order of array depth unless you specify a #weight for everything, then it will order by weight.
So if you don't want to use weights you could have done it like this although the suggestion above using #prefix is better for your case:
foreach ($categories as $key => $title) {
$form['slider']['head'][$key] = array(
'#type' => 'markup',
'#value' => "<div id='sliderHeaders'>Header Text</div>"
);
$form['slider']['vote'][$key] = array(
'#type' => 'slider',
'#title' => $title,
'#name' => $key, // TODO: define it with the $key variable.
'#options' => $options,
);
}
Slider is not a valid type. Are you using another module to provide that type?
If so:
foreach ($categories as $key => $title) {
$form['vote'][$key] = array(
'#type' => 'slider',
'#title' => $title,
'#prefix' => t("<div id='sliderHeaders'>Header Text</div>"),
'#name' => $key, // TODO: define it with the $key variable.
'#options' => $options,
);
}
Use the #prefix form attribute.