We have baked a crud with validations. All seems ok.
However, when we hit the submit button,
<?php echo $this->Form->submit('go for it'); ?>
and if we get validation errors, the HTML submit button loses is value attribute.
Before hitting submit we get this output:
<input type="submit" value="go for it"/>
After hitting submit we get this output:
<input type="submit" value></input>
Here's the full ctp code:
<?php echo $this->Form->create('ScheduleAccess'); ?>
<?php echo $this->Form->input('id'); ?>
<fieldset class="short">
<legend>Bla bla</legend>
<?php echo $this->Form->input('schedule_es', array('label' => 'Bla bla (es)')); ?>
<?php echo $this->Form->input('schedule_en', array('label' => 'Ble ble (en)')); ?>
</fieldset>
<fieldset class="short">
<legend>Last Bla bla</legend>
<?php echo $this->Form->input('last_entry', array(
'dateFormat' => 'YMD',
'timeFormat' => '24',
'label'=>'until:'
)); ?>
</fieldset>
<fieldset class="full">
<legend>terms</legend>
<div class="medium wysihtml5">
<?php echo $this->Form->input('free_entry_day_time_es', array('label' => 'Things (es)')); ?>
<?php echo $this->Form->input('free_entries_and_discounts_es', array('label' => 'More things (es)')); ?>
</div>
<div class="medium wysihtml5">
<?php echo $this->Form->input('free_entry_day_time_en', array('label' => 'Things (en)')); ?>
<?php echo $this->Form->input('free_entries_and_discounts_en', array('label' => 'More things (en)')); ?>
</div>
</fieldset>
<?php //echo $this->Element('admin/save'); ?>
<?php echo $this->Form->submit('go for it'); ?>
<?php echo $this->Form->end(); ?>
Has anyone found a similar issue?
just for grin's try this
<?php echo $this->Form->end('Go for it'); ?>
end can provide the submit button. If this works then you probably have something overwriting the value of the submit. I'd start looking in your $this->request->data to see what its sending over to the view.
Hope this helps.
Related
My program brings a list of a teacher from a table.
Then I want to show the names in the drop-down but for some reason, it opens an empty dropdown with the number of empty lines like the records in the table.
This is my code for this problem
<div>
<label for="teacher_name"> שם המורה: </label>
<select name="teacher_name" id="teacher_name">
<?php if (empty($teachers)): ?>
<p> No teachers found</p>
<?php else: ?>
<?php if($status == 'new'): ?>
<option value="please_select">נא לבחור</option>
<?php foreach ($teachers as $teacher): ?>
<option value=<?=$teacher['teacher_name']; ?> name="teacher_name" id="teacher_name"></option>
<?php endforeach; ?>
<?php endif; ?>
<?php if($status == 'edit'): ?>
<p> edit</p>
<input type="text" name="teacher_name" id="teacher_name" value="<?= htmlspecialchars($lesson->teacher_name); ?>" >
<?php endif; ?>
<?php endif; ?>
</select>
</div>
If you "view source" of your output I think you will see that the option tags do have data in them - but you haven't set the value to display, it should be more like <option ....>Show this in the list</option>.
Try this (the same code as you were using, but adding the teacher name variable again where it will display)
<option value=<?=$teacher['teacher_name']; ?> name="teacher_name" id="teacher_name"><?=$teacher['teacher_name']; ?></option>
I can log in a user using Auth->login($this->data). Debugging the Auth->user() after login all I see is the username and password. Is the Id supposed to be auto populated or do I need a way to manually set it? By going off a few tutorials it seem like the ID should already be there.
What is debugged:
\app\Controller\UsersController.php (line 90)
array(
'User' => array(
'password' => '*****',
'username' => 'LittleRy'
)
)
As ndm comment, I changed the call to Auth->login() so it should be grabbing the request info. With this change login() is always returning false. Below is the login form. I believe everything is being passed in correctly.
<div class="users form">
<?php echo $this->Session->Flash('auth');
?>
<?php echo $this->Form->create('User'); ?>
<fieldset>
<legend>
<?php echo __('Please enter your username and password'); ?>
</legend>
<?php echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>
try this $this->Auth->user('id'); to get user id.
I have got the following code in my edit.ctp:
<div class="employees form">
<?php echo $this->Form->create('Employee'); ?>
<fieldset>
<legend><?php echo __('Edit Employee Details'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('employee_name', array('required'=>false));
echo $this->Form->input('date_hired',array('required'=>false,'id'=>'datepicker','type'=>'text'));
echo $this->Form->input('employee_phone_number', array('required'=>false));
echo $this->Form->input('employee_email', array('required'=>false));
echo $this->Form->input('employee_address');
echo $this->Form->input('employee_dob',array('required'=>false,'id'=>'datepicker2','type'=>'text'));
echo $this->Form->input('access_level', array('required'=>false, 'options' => array('admin' => 'Admin', 'staff' => 'Staff')));
echo $this->Form->input('employee_username', array('required'=>false));
echo $this->Form->input('employee_pw', array('required'=>false));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
At the moment when I go in to the edit view, all fields get populated with existing data. I want the password field to be kept blank even if a password already exists. How can I do that?
echo $this->Form->input('employee_pw', array('type'=>'password', 'value'=>'', 'autocomplete'=>'off'));
I'm working with CakePHP version 2.3
I've been wondering how to save a looped form like phpmyadmin does when you input multiple form for 1 table.
Let's say that I have a table products with id, name and content columns.
In order to save my data, I make a form with this 3 inputs multiplied by 3.
So that gives me something like this :
<?php echo $this->Form->create('Product'); ?>
<!-- Form for product 1 -->
<?php echo $this->Form->input('name', array('label' => "Name")); ?>
<?php echo $this->Form->input('content', array('label' => "Content")); ?>
<?php echo $this->Form->input('id'); ?>
<!-- Form for product 2 -->
<?php echo $this->Form->input('name', array('label' => "Name")); ?>
<?php echo $this->Form->input('content', array('label' => "Content")); ?>
<?php echo $this->Form->input('id'); ?>
<!-- Form for product 3 -->
<?php echo $this->Form->input('name', array('label' => "Name")); ?>
<?php echo $this->Form->input('content', array('label' => "Content")); ?>
<?php echo $this->Form->input('id'); ?>
<?php echo $this->Form->end('done'); ?>
Of course this can't work and I have no clue to how to get this done.
Does anybody could show me how it works?
Thank you very much for your help.
Do the following calls to input() method:
...
echo $this->Form->input('Product.0.name', array('label' => 'Name'));
echo $this->Form->input('Product.0.content', array('label' => 'Content'));
echo $this->Form->input('Product.1.name', array('label' => 'Name'));
echo $this->Form->input('Product.1.content', array('label' => 'Content'));
echo $this->Form->input('Product.2.name', array('label' => 'Name'));
echo $this->Form->input('Product.2.content', array('label' => 'Content'));
...
The previous code should output the following form elements
<input type="text" id="Product0name" name="data[Product][0][name]">
<input type="teaxtarea" id="Product0Content" name="data[Product][0][Content]">
<input type="text" id="Product1name" name="data[Product][1][name]">
<input type="teaxtarea" id="Product1Content" name="data[Product][1][Content]">
<input type="text" id="Product2name" name="data[Product][2][name]">
<input type="teaxtarea" id="Product2Content" name="data[Product][2][Content]">
which can posted and saved by your controller using saveAll() method very easily.
Also check out the CakePHP docs at: Field-naming-conventions
I can get Cake to output a submit button using the following PHP:
<?php echo $this->Form->end(__('Submit')); ?>
which outputs this HTML:
<input type="submit" value="Submit">
but I want to use a specific input class to get the following:
<input type="submit" value="Submit" class="some class">
is this possible?
Thank you :).
Yes it's possible :
<?php
echo $this->Form->submit(__('Submit',true), array('class'=>'some class'));
echo $this->Form->end();
?>
Which is documented here.
This should do the trick:
<?php echo $this->Form->end(array('label' => __('Submit', true), 'class' => 'some class')); ?>