【发布时间】:2018-05-14 20:23:45
【问题描述】:
我正在根据here 给出的示例创建一个无模式表单。一旦用户单击提交按钮,我就会从数据库中检索一些信息并将其显示在表单下方的表格中。当我点击提交按钮时,表单每次都会显示start 和end 的默认值,这导致我的用户使用该页面时感到有些困惑。
有没有办法让FormHelper 显示最终用户提交的值而不是默认值?
src/Form/StartEndForm.php
namespace App\Form;
use Cake\Form\Form;
class StartEndForm extends Form{
protected function _buildSchema(Schema $schema) {
return $schema->addField('start', [
'type' => 'date',
'default' => new Time('-1 month')
])
->addField('end', [
'type' => 'date',
'default' => new Time()
]);
}
protected function _buildValidator(Validator $validator) {
return $validator->add('start', 'date', [
'rule' => ['date'],
'message' => 'Please provide a valid date'
])
->add('end', 'date', [
'rule' => ['date'],
'message' => 'Please provide a valid date'
]);
}
protected function _execute(array $data) {
//do some SQL stuff and return the value
}
}
src/Template/Logs/index.ctp
echo $this->Form->create($form, [
'class' => 'start-end-date',
'type' => 'get'
]);
echo $this->Form->input('start');
echo $this->Form->input('end');
echo $this->Form->submit('Submit');
echo $this->Form->end();
//If values were returned, create a table
foreach(....)....
【问题讨论】:
标签: php cakephp cakephp-3.x