Turn off pluralization of class names in cakephp - forms

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

Related

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.

how to add form id in cakephp when creating a form

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

CakePHP Text as Form Submit

I've searched the web and have come up with nothing. (Multiple search engines too - I have looked!)
I'm trying to have a text link as the 'form submit' button. Any ideas if this is possible in CakePHP?
Current view code below!
<?php
echo $this->Form->create('trainees', array(
'action' => 'reassign'
));
echo $this->Form->input('emailaddress', array(
'value' => 'scott#something',
'type' => 'hidden',
));
echo $this->Form->submit('Re-Assign Mentor', array(
'class' => 'submit mid',
'before' => '<p>',
'after' => '</p>'
));
echo $this->Form->end();
?>
You need to use the HtmlHelper to output a link. In it's simplest form you use the text you want displayed with the URL that it should link to. In this case it will be JavaScript:
$this->Html->link('Submit Form', 'javascript:document.forms["myform"].submit();');
There are two additional parameters (a $options array and $confirmMessage boolean), but they along with the URL are optional.
You can also call your own JavaScript function if you need to do client side verification and call the submit function from there (also verify on the server as clients can lie).
http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link

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.

Redirection from module to application

how can we go back form one module to parent application in ZEND. I use this code:-
<?php echo $this->url(array('controller' => '', 'action' => '')); ?>
If you add a 'module' key to the URL array, you can easily traverse modules. If you're trying to get to the "Parent" (the default module, perhaps?), you'd change your code to:
<?php echo $this->url(array('module' => 'default', 'controller' => 'index', 'action' => 'index)); ?>