how to add form id in cakephp when creating a form - forms

i am new in cakephp so i dont know how can i do this ..
i want to add custom form id in my form but it is not adding the id ..it is using the default one adding the 'UserIndexForm' id..
how can i add this id
i want to do like this
<form method="post" action="#" id="form-login">
here cakephp code
<?php
echo $this->Form->create('User', array(
'inputDefaults' => array(
'label' => false,
'div' => false,
'id' =>'form-login'//not working
)
));
?>
please help me if anyone know this
thankyou in advance

The inputDefaults option is only changing the input fields so you need to set the id on the root level of the array:
<?php
echo $this->Form->create('User', array(
'id' => 'form-login',
'inputDefaults' => array(
'label' => false,
'div' => false
)
));
?>

Related

Turn off pluralization of class names in cakephp

How to Turn off pluralization altogether in cakephp2.2
This is the source code of my page:
<form action="/scores/exam2014s/aview" id="exam2014AviewForm" method="post" accept-charset="utf-8">
In the above code suffix - 's' in 'exam2014s' is appearing automatically, which i dont want kindly help how to avoide the pluralization of the above.
In the bootstrap.php, I have used the following code enter code hereto turnoff pluralization:
Inflector::rules(
'plural',
array(
'rules' => array('/^([a-zA-Z_-]*)$/i' => '\1'),
'irregular' => array(),
'uninflected' => array()
)
);
With the above code in bootstrap I could not fix the problem.
Code in my index.ctp is below:
echo $this->Form->create('exam2014', array('action' => 'aview'));
echo $this->Form->label('Page.name','Name: ',null);
echo $this->Form->input('qr_code');
echo $this->Form->submit();
echo $this->Form->end();
Thanks in advance.
Sai Krishna
why not simply the following code?
echo $this->Form->create(
'exam2014',
array(
'url' => array('controller' => 'exam2014', 'action' => 'aview')
)
)
Since Cake2.x the form posts to itself by default.
So simply do:
echo $this->Form->create('Exam2014');

Individual class option for radio buttons

Is there an individual class option for radio buttons in Cake 2.x?
In my opinion the logical approach would be like:
<div class="input radio required">
<?php
$options = array(
array('1' => 'Kuchen', 'class' => 'cake'),
array('2' => 'Kekse', 'class' => 'biscuits'),
array('3' => 'Eis', 'class' => 'iceCream'),
);
$attributes = array(
'legend' => false,
'default' => '1'
);
echo $this->Form->radio('INCOMETYPE', $options, $attributes);
?>
</div>
But that doesn´t work. I hope you can help. Thanks :)
You could extend FormHelper to add implement this functionality if you intend to use it elsewhere. If it's a one off, you might be better to produce the markup by hand. Use the code produced by $this->Form->radio to give you a start.

populate values from data base in select box in zend framework

I am new in zend framework. I want to populate company name and company id from database to select box. in zend
example as we do it PHP
<option value="<?php echo id ?>" > <?php echo $comapnyName ?>
this is my form
$this->addElement('select', 'companyName', array(
'required' => true,
'filters' => array('StringTrim'),
'style' => array('width:103px'),
'decorators'=> array(
'ViewHelper','Errors'
)
));
help me
The parameter name is multiOptions and requires an array with the value=>companyName pairs for your option elements.
So either add it to your statement above when you create the element or later with $element->setMultiOptions($options)

Display boolean as radio button in CakePHP form

Does anyone know how to display two radio buttons in a form in CakePHP and have them save to a boolean field in the DB?
I can get my boolean value to display as a checkbox (default behaviour) but I need to display two radio buttons, however when I do this the changes don't get saved to the DB.
I feel like it's something very simple. Here's my code:
<h1>Edit Content</h1>
<?php
$thisVal = $this->data['LessonContent']['is_exercise'] ? "1" : "0";
$options = array(
'0' => 'Learning Material',
'1' => 'Exercise'
);
echo $this->Form->create('LessonContent', array('action'=>'edit'));
echo $this->Form->input('name', array('label' => 'Name'));
echo $this->Form->input('description', array('label' => 'Description'));
echo $this->Form->input('is_exercise', array(
'type' => 'radio',
'class' => 'radio',
'legend' => false,
'name' => 'Type',
'options' => $options,
'value' => $thisVal
));
echo $this->Form->input('id', array('type'=>'hidden'));
echo $this->Form->input('lesson_id', array('type'=>'hidden'));
echo $this->Form->end('Save Content');
echo $this->Html->link('Cancel', array('controller'=>'Lessons', 'action'=>'view', $this->data['Lesson']['id']));
?>
Thanks
You're overriding the name of the input, therefore the value for is_excercise will be sent as Type.
Remove the name option;
echo $this->Form->input('is_exercise', array(
'type' => 'radio',
'class' => 'radio',
'legend' => false,
'options' => $options,
'value' => $thisVal
));
note after making this change, you probably don't even have to manually set the value of the radio-button.
debugging
In situations like this, always check/debug the posted form-data, either via FireBug or by debugging it in CakePHP, by putting this in your controller;
debug($this->request);
Even better, install the CakePHP DebugKit Plugin this plugin shows all the information (request data, queries, session variables etc.) without having to add debug-lines

Cakephp form creation gives me missing database table

According to the manual, I should be able to do this which is to leave Model as null
<?php
echo $this->Form->create(null, array('url' => '/recipes/add'));
// or
echo $this->Form->create(null, array(
'url' => array('controller' => 'recipes', 'action' => 'add')
));
But in reality, I got error saying missing database table? Why?
I have my Model which is not directly mapping to any table. Why can't I leave it as null? Something like this:
<?php echo $this->Form->create(null,array('url' => array('my_account','action' => 'change_avatar'),'type' => 'file'));?>
Try passing false for the model instead of null:
<?php
echo $this->Form->create(false, array('url' => '/recipes/add'));
// or
echo $this->Form->create(false, array(
'url' => array('controller' => 'recipes', 'action' => 'add')
));
From the manual:
You can also pass false for $model. This will place your form data into the array: $this->request->data (instead of in the sub-array: $this->request->data['Model']). This can be handy for short forms that may not represent anything in your database.
make a table with name recipes in your database. The submitted date from the form will be saved at recipes table.