Impossible to show CakePhp CheckBox - checkbox

I'm developping my application and I got stuck with a little problem.
I have to use checkboxes but when declaring them i got nothing on my view, i mean that the checkbox doesn't appear
echo $this->Form->input('Class.id', array(
'options'=>$classes,
'type'=>'select',
'multiple' => 'checkbox'));
Please could anyone help!
Thanks

Use echo $this->Form->checkbox('name');

Related

Selector for input checkboxes Drupal 7

I am trying to hide a field based on what user is selecting from a entity referenced checkbox list but no matter what I do I cannot hide the field.
I think some issue with the selector.
$form['title']['#states']['invisible'][] = array(
'input[name="field_offering_course[und][0][target_id]"' =>array('checked' => TRUE));
You are missing a bracket:
'input[name="field_offering_course[und][0][target_id]"]' =>array('checked' => TRUE));
I can't help more than that...not very experienced in php :D

CakePHP 2 with CakeDC/I18n language prefix being lost

I have a CakePHP 2.5 site running with CakeDC/I18n plugin to allow for multi language support. I have installed the plugin to use a 3 letter prefix when switching languages:
www.example.com/eng/
This is working fine when I click a button to change languages. The language prefix is added to the url. The problem is when I switch pages by clicking on a link the prefix is dropped. Why would this be happening? Do I need to do something in the href markup? My understanding is that the CakeDC/I18n plugin would take care of this.
Any help would be greatly appreciated as I have been scratching my head with this one for awhile!
You need to pass as parameter the current language.
Otherwise it'll always use the default language that you defined in the bootstrap.php
Here is an example.
Router::url(
'lang' => 'spa',
'controller' => 'articles',
'action' => 'view',
'slug' => 'test'
);

How should I handle forms in CakePHP?

I'm studying CakePHP. I read a CakePHP book, and web tutorials, but I still don't get some basic things:
I see people always create a form in View with $form->create. Can I use an HTML form like normal, or must do exactly like people do?
When a form is created in login.ctp with this code:
echo $form->create('User', array('method' => 'POST', 'action' => 'login'));
echo $form->input('email');
echo $form->input('password');
echo $form->input(array('type' => 'submit'));
echo $form->end('Login');
When I click the submit button, will the data be passed to the function login() in the Controller class?
Edited :
I tried this :
<?php
$this->Form->create("Test");
$this->Form->input("stuId",array('class'=>'inputField', 'placeholder'=>'SVxxxxxxxx'));
$this->Form->input("stuName",array('class'=>'inputField', 'name'=>'stuName'));
$this->Form->end();
?>
But it show nothing ? what is the problem :(
But it show nothing ? what is the problem :(
You have to use echo as in your first code snippet:
echo $this->Form->create("Test");
echo ...
You can use HTML for anything you want, but you'd be losing a big advantage of the CakePHP framework. The Cake HTML and form helpers help to future-proof your code. You also get the benefit of Cake's implementation of best practices in web coding. I fully recommend using those helpers.
The form data is passed to $this->request->data.
Yes, the parameters will be passed to login method.
I see $form being used in the form there, it appears you are using older version of cakephp (if $form has been instantiated with $this->Form then you are fine)
The FormHelper does lot of automagic for us and it also provides us means for added security.
I would reckon you to go with The Blog tutorial

get data from combobox

Hi there i want to get data from the below combo box in cakephp for comparison.
echo $form->input('ac_owner', array('label' => 'Account Owner',
'options' => array('A','B','C'), 'default' => 2));
is it possible to get this value using javascript
please help.
thank you in advance........
The result of this is a normal <select> element that can of course be accessed by Javascript. The id, if you're looking for that, should be something along the lines of ModelNameAcOwner. Inspect the resulting HTML or DOM tree to find it.

CakePHP: Field label in model

Are there any approaches to set in model field label? I dont want use 'label' property in form helper.
Please make sure I understand this correctly, you want to set a field label in the model, rather than using the form helper?
That violates basic MVC architecture. While Cake is flexible on some things, I don't think this is a possible option. I also don't see why you'd want to do it -- is there some reason that you don't want to use the label property in the form helper?
The basic issue is that the label for a form is part of the presentation layer, while the model represents the data. As such, it isn't possible (and I can't think of a situation where it'd make sense...) to assign a label to a data field which would then be used whenever that field is output.
If I misunderstood your question, please clarify.
What I do is setting up a convention in my models. I added a public attribute called "fieldLabels" to all the models, to assign default text labels for generic forms.
Example:
class MyModel extends AppModel {
// ...
public $fieldLabels = array(
'username' => 'User name',
'email' => 'e-mail address',
'phone' => 'Phone No.',
);
// ....
}
Then I pass around the labels to the view and use the extra parameter for the input, as sibidiba said:
echo $this->Form->input('title', array(
'label' => $fieldLabels['title'] . ': ',
));
In case I need special labels, I'll handle each case as an exception. Of course, if you want internationalization, that's a whole different topic.
Do you want to set the label's value? This is done in the view, but of course the value can originate from the controller/model. Like this:
echo $this->Form->input('title', array(
'label' => $titleLabel,
));
you can also disable the label element:
echo $this->Form->input('title', array(
'label' => null,
));
Not 100% sure, but I think you might be looking for Model::displayField
i suggest u directly use the helper u want.. bcos $form-input() creates div .. labels..
i personally had to weed out this on each line
with the direct helper like
$form->text()
$form->textarea()
$form->select()
u can keep the code much cleaner.
Note: $form->input saves time when used right...

Resources