I am unable to set the id of the form or the class of the submit button. I seen examples that follow my code but I am not getting either set.
I am using cakePHP 2.5.
<?php
echo $this->Form->postLink(
'Confirm',
array('controller' => 'assets', 'action' => 'delete'),
array('id' => 'testId', 'class' => 'btn btn-confirm')
);
?>
What I get is
<form action="/assets/ajax_delete/56.json" name="post_53ac1bb05415c464261170" id="post_53ac1bb05415c464261170" style="display:none;" method="post">
<input type="hidden" name="_method" value="POST">
</form>
Confirm
<?php echo $this->Form->postLink('Confirm', array('controller' => 'assets', 'action' => 'delete', $yourId), null, __('Are you sure you want to delete # %s?', $yourId)); ?>
Related
I have this link that I use to for my modal
<?php
echo $this->Html->link('Create Schedule', '#', array('id' => 'createSchedule', 'class' => 'btn btn-success', 'role' => 'button', ));
?>
How do I convert it to $this->Form->end() format?
Thank you!
You can do this also
<?php
echo $this->Form->button("Create Schedule", array("id" => "createSchedule", "class" => "btn btn-success", "type" => "submit"));
echo $this->Form->end();
?>
or you could also do this
<?php
echo $this->Form->submit("Create Schedule", array("id" => "createSchedule", "class" => "btn btn-success"));
echo $this->Form->end();
?>
You can try this
<?php
$options = array(
'label' => 'Create Schedule',
'id' => 'createSchedule',
'class' => 'btn btn-success'
);
echo $this->Form->end($options);
?>
example:
<a class="btn btn-mini" href="#"><i class="icon-star"></i> Star</a>
i try by Html::Helpers like
echo $this->Html->link($this->Html->tag('i','',
array('class' => 'btn')), array('action' => '../link'));
but it not work !
try:
echo $this->Html->link(
$this->Html->tag('i', '', array('class' => 'icon-star')) . " Star",
array('action' => 'your_action'),
array('class' => 'btn btn-mini', 'escape' => false)
);
I am using cakephp 2.1 and I used login action in UsersController as follows.
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Invalid email or password, try again', 'default/flash_error');
}
}
}
And the login.ctp code is as follows.
<?php echo $this->Form->create('User', array('class' => 'form')); ?>
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<?php echo $this -> Form -> text('email', array('id' => 'inputEmail', 'placeholder' => 'Email')); ?>
<?php echo $this -> Form -> error('email', null, array('wrap' => 'span', 'class' => 'help-block')); ?>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<?php echo $this -> Form -> password('password', array('id' => 'inputPassword', 'placeholder' => 'Password')); ?>
<?php echo $this -> Form -> error('password', null, array('wrap' => 'span', 'class' => 'help-block')); ?>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"/>
Remember me </label>
<?php echo $this->Form->button('Sign in', array('type' => 'submit', 'class' => 'btn')); ?>
</div>
</div>
<?php echo $this->Form->end(); ?>
When the form get submitted with email and password, the user is not able to login so its showing an error 'Invalid email or password, try again'. Even I am passing the $this->request->data['User'] into $this->Auth->login() method and debugged $this->Session->read(Auth.User.id). Its giving me null. Please give me a solution for this.
You can try passing $this->request->data into the $this->Auth->login() method. It's not a great way to do it (see this post: CakePHP Auth Component Not logging in when using $this->Auth->login();), but it works for me. Have you debugged $this->Auth->login()?
I am trying to add below style..
<div class="rowElem noborder">
<label>Language:</label>
<div class="formRight noSearch">
<select name="select2" class="chzn-select">
<option value="opt1">Choose the Language</option>
<option value="opt2" selected="selected">Kannada</option>
<option value="opt3">Telugu</option>
<option value="opt4">Tamil</option>
</select>
</div>
<div class="fix"></div>
</div>
But in cakephp, I have this code
<?php echo $this->Form->input('language_id', array('class' => 'chzn-select' )); ?>
Please give me the solution..
If I understand what you are asking, this is what you need to do.
In your controller you will create your options array for the select box:
$this->set('languageOptions', array('opt1' => 'Choose Language', 'opt2' => 'Kannada', 'opt3' => 'Telugu', 'opt4' => 'Tamil'));
Then in the view, you create the form:
<div class="rowElem noborder">
<label for="language_id">Language:</label>
<?php echo $this->Form->input('language_id', array('class' => 'chzn-select', 'options' => $languageOptions, 'label' => false, 'div' => array('class' => 'formRight noSearch'))); ?>
<div class="fix"></div>
</div>
$langs = array('opt1' => 'Choose Language', 'opt2' => 'Kannada', 'opt3' => 'Telugu', 'opt4' => 'Tamil');
$this->set(compact('langs')); // if you set options from controller
Then in view try this:
$this->Form->input('language_id', array(
'type' => 'select',
'options' => $langs,
'selected' => 2 // suppose default select Kannada
)
);
Cake Php Select Option Code
Language:
Form->input('language_id', array('class' => 'chzn-select', 'options' => $languageOptions, 'label' => false, 'div' => array('class' => 'formRight noSearch'))); ?>
I'm new in cakephp. What I try to accomplish is this output :
<p><label> </label><input class="adminbut rad2" type="submit" name="submit" value="Login" /></p>
And this is what I did in my view file
<?php echo $this->Form->end(array(
'div' => false,
'label' => 'Login',
'class' => 'adminbut rad2',
'name' => 'submit',
'value' => 'Login',
'before' => '<p>',
'after' => '</p>'
));?>
And what I got is :
<input class="adminbut rad2" name="submit" value="Login" type="submit" /></p>
And as you can see, my output is missing :
<label> </label>
Any solution?
Thanks :)
Try
$form->create();
$form->submit("Login",array( 'div' => false, 'class' => 'adminbut rad2', 'name' => 'submit', 'value' => 'Login', 'before' => '<p><label> </label>', 'after'
=> '</p>'
));
$form->end();
echo $form->input('submit', array(
'type'=>'submit',
'value'=>'Login',
'class'=>'adminbut rad2',
'div'=>array('tag'=>'p'),
'label'=>" "
));
Try This my friend
Cakephp 2.X
$this->Form->submit(__('Submit'), array('class'=>'adminbut rad2'));
Cakephp 1.x
$form->submit(__('Submit'), array('class'=>'adminbut rad2'));