CodeIgniter, form helper - Adding classes to the elements - php

So i created a form with the CodeIgniter Form helper. I'm trying to give some form elements a class, but something strange happens. I do it like this:
echo form_input('title', $this->input->post('title'), 'class="titleInput"');
When i inspect the element it actually shows the class is there:
but it doesn't take any of the property's given in the CSS file. Also when i do something ugly like:
echo form_input('title', $this->input->post('title'), style="height=30px");
When i inspect the element i get this:
But it doesn't actually do anything with the styling given.
Hopefully someone can give me a hand here!

$data = array(
'name' => 'title',
'value' => $this->input->post('title'),
'class' => 'titleInput',
'style' => 'height:30px'
);
echo form_input($data);
reference

Related

Yii2: How can I place something into a Breadcrumbs widget?

I find the Breadcrumbs widget quite useful. However, on the right side within the widget there is enough space for something else. If I'd like to put a link ('a' tag, but could be actually any other small thing) right aligned into the Breadcrumbs, how could I do that? What is a simple and proper solution? Should I extend the class, develop my own, use begin and end of the widget somehow?
If you look at yii\widgets\Breadcrumbs you see that there is a third parameter in the breadcrumbs items
From the Yii2 file
[
'label' => 'Post Category',
'url' => ['post-category/view', 'id' => 10],
'template' => "<li><b>{link}</b></li>\n", // template for this link only
],
So by adding something like this in your main layout file
$this->params['breadcrumbs'][] = [
'label' => 'Your Label',
'url' => ['controller/action'],
'template' => "<li style="float: right;">{link}</li>\n"
];
you will get a link at the right side. This link will come with a / prefixed, but you can bind it to a .class instead and configure it the way you want.
'template' => "<li class=\"yourClass\">{link}</li>\n"

ZF2 Input Filter Change Message Color

I made typical form with ZF2 form and wanted to add validation using ZF2 InputFilter. It was success but the colour of error message is black which is looks strange. I tried to change the colour by using method I've searched like this:
array(
'name' =>'NotEmpty',
'options' => array(
'messages' => array(
NotEmpty::IS_EMPTY => '<div style="color:red;">Please enter User Name!</div>'
),
),
),
But, instead of message's colour changed to red, it showed the tag with style, in other word, just plain HTML. What is the proper way to achieve my need?
Easiest way would be to modify the view helper ;)
Inside your module.config.php
'view_helpers' => [
'factories' => [
'formelementerrors' => function($vhm) {
$fee = new \Zend\Form\View\Helper\FormElementErrors();
$fee->setAttributes([
'class' => 'your error classes'
]);
return $fee;
}
]
]
The alternate approach when rendering errors using $this->formElementErrors() would be to add the error classes inside the ViewHelper directly
$this->formElementErrors($element, ['class' => 'my error classes']);

CakePHP form appending div and label automatically

I am using Cakephp 2.2.3 version. When I create form using Cake form helpers, it automatically appends a div and label to the input type field. How to avoid it?
Following is the code:
<?php echo $this->Form->input('username', array('id' => 'username', 'class' => 'login-inp', 'type' => 'text')); ?>
You can use options array of input to avoid form appending div and label automatically. Set div and label of options array to false.
echo $this->Form->input('username',
array('id' => 'username', 'class' => 'login-inp',
'div' => false, 'label' => false
)
);
That's what FormHelper::input() is supposed to do. If you don't want the label and wrapping div just use the functions to generate specific input elements only like FormHelper::text(), FormHelper::select(), FormHelper::radio(), etc.

How to add a class to all the input elements inside a form in cakephp

How do i use the inputDefaults to add a common class to all the input elements in my form. also pls give a brief description of the inputDefaults.
isn't it:
echo $this->Form->create('User', array(
'inputDefaults' => array(
'class' => 'someclass'
)
);
`
You should read the cookbook. theres a good example: http://book.cakephp.org/view/1639/options-inputDefaults
When you create a form you add inputdefaults key in options:
echo $this->Form->create('User', array(
'inputDefaults' => array(
'div' => array('class' => 'someclass')
)
);
After browsing the source file i didn't find anything either. So the only way is to use it explicitly for every call to the input function.

Pass Element value to $ajax->link in cakephp

I need to pass the value of an element to an $ajax->link without using a form/submit structure. (because I have a dynamically set number of clickable links through which I am triggering the action)
I used to do this in Ruby using the Prototype javascript function $F like this:
<%= link_to_remote "#{item.to_s}",
:url => { :action => :add_mpc },
:with => "'category=' + $F('mpc_category')" -%>
But this does not seem to work in Cakephp:
<?php echo $ajax->link(substr($vehicle['vehicles']['year'], -2),
array('action' => 'add_mpc', 'category' => '$F("mpc_category")'),
array('update' => 'results', 'position' => 'top')); ?>
PHP sees $F as a variable instead of a call to javascript. I'm not too familiar with Javascript, but is there another way to pass the value of the 'mpc_category' input element to the controller through this link? I have been looking for a couple days and can't find anyone dealing with this specific issue. Thanks for any assistance.
Edit: fixed syntax in php statement.
haven't really used cake, but I have used rails. The js part should be entirely a string. Probably something like this:
<?php echo $ajax->link(substr($vehicle['vehicles']['year'], -2),
array('action' => 'add_mpc', 'category' => "$F('mpc_category')"),
array('update' => 'results', 'position' => 'top')); ?>
I'm assuming that it tacks "$key=$value" onto the params in the ajax link. Also note you were missing a comma at the end of that second line.
After working on this for a couple days now, the best I have come up with is this:
<?php echo $ajax->link($year,
array( 'action' => 'add_row',
'category' => $category,
'product' => $product.$newpart,
array( 'update' => $summary['summary']['id']." ".$vehicle['vehicles'],
'with' => "$('app_select').serialize()")); ?>
the 'with' => "$('app_select').serialize()" being the part that grabs the values out of the form without having to submit the form.
I only needed one of the form elements, however, so this is not ideal as it passes the entire serialized form to the controller.
I would still like to be able to do this with any element, regardless of it is in a form or not, but this method doesn't seem to do that. Perhaps someone more familiar with prototype could shed some light on that.

Categories