Select box changed to Readonly when displayed on modal in symfony? - symfony

I am making form in symfony, I create a select box product in ProductType.php :
$form->add(
'product',
ChoiceType::class,
[
'choices' => array_flip($product),
'label' => 'Product',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control film-list not-chosen'],
'placeholder' => '-- Select product --',
'multiple' => false,
'required' => false
]
);
in View :
<?php echo $view['form']->start($form); ?>
<div class="col-md-12">
<div class="row">
<div class="col-md-6">
<?php echo $view['form']->row($form['product']); ?>
</div>
</div>
</div>
<?php echo $view['form']->end($form);
And it shows successfully on the theme. But my theme uses modal of bootstrap. When shown above, my select box is changed to readonly, cannot enter keywords. Where did I go wrong. Please everyone help me.
Update:
I have added 'readonly' => false to attr in the form but it still doesn't work.

Related

Shortcode does not render my form, rather showing its name as text

I have started learning WordPress recently. I am trying to create a custom form for users to post data using a custom post type which I have created without plugin. For this I have created a custom plugin and activated it from admin. But when the page loads I don't see the form, rather it displays the name of shortcode as text. I already checked another StackOverflow post Shortcode rendering as text not as shortcode should but could not understand properly how it relates to my problem.
My plugin looks like this:
<?php
/*
Plugin Name: Custom frontend entry form
Description: Custom frontend entry form for publishing trip reports by users
Version: 1.0
Author: Subrata Sarkar
*/
/* Register Custom Post Type */
function trip_report_init() {
//Set up labels
$labels = array(
'name' => 'Trip Report',
'singular_name' => 'Trip Report',
'add_new' => 'Create New Report',
'add_new_item' => 'Create New Report',
'edit_item' => 'Edit Trip Report',
'new_item' => 'New Trip Report',
'all_items' => 'All Trip Reports',
'view_item' => 'View Trip Report',
'search_items' => 'Search Trip Reports',
'not_found' => 'No Trip Report Found',
'not_found_in_trash' => 'No Trip Report found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Trip Reports'
);
//register_post_type
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'trip-reports'),
'query_var' => true,
'menu_icon' => 'dashicon-normalize',
'supports' => array(
'title',
'editor',
'excerpt',
'comments',
'author',
'thumbnail',
'page-attributes'
)
);
register_post_type('trip_report', $args);
//register taxonomy
register_taxonomy('report_category', 'trip_report', array(
'hierarchical' => true,
'label' => 'Report Category',
'query_var' => true,
'rewrite' => array('slug' => 'report-category')
));
//echo 'Trip report entry form';
}
add_action('init', 'trip_report_init');
/* Ends registration */
/* Build the form */
function trip_report_entry_form() { ?>
<form id="trip-report-entryform" name="trip-report-entryform" method="post" action="">
<div class="row">
<div class="col-md-12">
Report title <i class="red-text">*</i>
<input type="text" id="txtTitle" name="txtTitle" class="form-control" maxmaxlenght="30" required />
</div>
<div class="clearfix"></div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" value="Submit" class="btn btn-primary text-small" />
</div>
<div class="clearfix"></div>
</div>
</form>
<?php }
/* Ends form */
add_shortcode('new_trip_report', 'trip_report_entry_form');
//if ( shortcode_exists( 'new_trip_report' ) ) { echo "The shortcode exists";}
?>
But when I add the shortcode in a page content editor, the page does not render the form rather it only displays the name of the shortcode as text.
Screenshot:
I referred http://teachingyou.net/wordpress/wordpress-post-from-the-front-end-with-a-custom-post-type/
To my knowledge I could not find any difference between the reference code and that of mine. What is wrong in my approach?
There are 2 issues in your code.
Shortcodes should return a value; they shouldn't output directly.
Your shortcode is registered as new_trip_report while you're attempting to use new-trip-report
Return the HTML in your shortcode callback and update the registration.
function trip_report_entry_form() {
return '<form id="trip-report-entryform" name="trip-report-entryform" method="post" action="">
<div class="row">
<div class="col-md-12">
Report title <i class="red-text">*</i>
<input type="text" id="txtTitle" name="txtTitle" class="form-control" maxmaxlenght="30" required />
</div>
<div class="clearfix"></div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" value="Submit" class="btn btn-primary text-small" />
</div>
<div class="clearfix"></div>
</div>
</form>';
}
add_shortcode( 'new-trip-report', 'trip_report_entry_form' );
Further reading: https://codex.wordpress.org/Function_Reference/add_shortcode
The problem is your function trip_report_entry_form not returning anything.
replace that function with these codes:
function trip_report_entry_form($atts) {
$out = '';
$out .='<form id="trip-report-entryform" name="trip-report-entryform" method="post" action="">
<div class="row">
<div class="col-md-12">
Report title <i class="red-text">*</i>
<input type="text" id="txtTitle" name="txtTitle" class="form-control" maxmaxlenght="30" required />
</div>
<div class="clearfix"></div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" value="Submit" class="btn btn-primary text-small" />
</div>
<div class="clearfix"></div>
</div>
</form>';
return $out;
}
In the post editor, make sure your characters aren't being escaped. On the top right of the content editor, switch from Visual to HTML. Your shortcode brackets come up as [ and ] if they're being escaped.

How to catch pages ids and showing the selected ones?

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

Yii2 Kartik DatePicker - CSS

I am starting to use the Yii2 Kartik helpers.
The issue i am having is the CSS of the datepicker
As you can see the Date of Birth field has no padding at the bottom.
The code for the fields around it
<?= $form->field($model, 'mobile')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'telephone')->textInput(['maxlength' => true]) ?>
<?= Html::activeLabel($model, 'date_of_birth') ?>
<?= DatePicker::widget([
'model' => $model,
'attribute' => 'date_of_birth',
'options' => ['placeholder' => 'Enter birth date ...'],
'pluginOptions' => [
'autoclose'=>true,
'format' => 'dd-mm-yyyy',
]
]); ?>
<?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'user_id')->textInput() ?>
From the CSS i can see that the Kartik creates a div with the class input-group
<div id="staff-date_of_birth-kvdate" class="input-group date">
Where as the standard form element have a div with the class form-group
<div class="form-group field-staff-telephone">
Any ideas?
Regards
Liam
You should simply try :
<?= $form->field($model, 'date_of_birth')->widget(DatePicker::className(), [
'options' => ['placeholder' => 'Enter birth date ...'],
'pluginOptions' => [
'autoclose'=>true,
'format' => 'dd-mm-yyyy',
],
]) ?>
Read more : http://demos.krajee.com/widget-details/datepicker#usage

CakePHP & Bootstrap - date field layout

Im beginning with both bootstrap and CakePHP 2.x. I baked my views with https://github.com/EKOInternetMarketing/BootstrapCake but there is a problem with date-fields layout. The view looks like this
<div class="form-group">
<?php echo $this->Form->input('booking_date', array('class' => 'form-control', 'placeholder' => 'Booking Date'));?>
</div>
But the problem is that CakePHP creates three selects from a date-field which are all 100% width, which messes up the form and the fields look like this, while it should be three selects side-by-side:
Apparently bootstrap 2 had classes for smaller selects, but bootstrap 3 doesnt anymore. Any ideas how to get it looking like it should?
For cakephp3, you have to do things a little differently:
echo $this->Form->input('booking_date', ['year' => ['class' => 'form-control'], 'month' => ['class' => 'form-control'], 'day' => ['class' => 'form-control'] ]);
http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-datetime-inputs
For input of type date in CakePHP you aren't able to wrap each select element by tag you like in standard way using div option, but there is 3 options which can handle it - between, separator and after. Below is example which set your selects inline.
<div class="form-group">
<?php echo $this->Form->input('booking_date', array(
'class' => 'form-control',
'placeholder' => 'Booking Date',
'div' => array('class' => 'form-inline'),
'between' => '<div class="form-group">',
'separator' => '</div><div class="form-group">',
'after' => '</div>'
));?>
</div>
If you using bootstrap grid you can get even better result using its classes to set this selects inline.

how to generate a textfield with customized height (yii textField)

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

Resources