【问题标题】:cakephp creating a form with user inputscakephp 使用用户输入创建表单
【发布时间】:2012-08-11 23:31:27
【问题描述】:

我试图创建一个视图,其中用户选择了他们创建的模板编号,然后转到下一页,在那里它会吐出他们为该模板创建的字段。我有我的 sql 语句做我想让他们做的事情,但我不确定如何让表单将这些 custom 字段 default_values 打印到输入框中

invoices 表包含id sender_id receiver_id template_id 字段表包含id name default_value active template_id

invoices hambt fields
fields hambt invoices

连接表是fields_invoices,它包含id invoice_id field_id entered value

我不确定如何从发票表和字段表中获取 id 以保存到连接表中

    public function create($id)
    {   
    $this->set('title_for_layout', 'Create Invoice');
    $this->set('stylesheet_used', 'homestyle');
    $this->set('image_used', 'eBOXLogoHome.png');   
    $this->layout='home_layout';

     if (!is_numeric($id)) throw new BadMethodCallException('I need an ID');
     $this->Invoice->id = $id;
     if (!$this->Invoice->exists()) throw new NotFoundException('Invalid ID');

    $this->set('invoice_id',$id);

    $names = $this->Invoice->find('list',array(
    'fields'=>array('template_id'),
    'conditions'=>array('id'=>$id)));

    $fields = $this->Field->find('list', array(
     'conditions'=>array(
     'template_id'=>$names)));

    $this->set('field',$fields);

    $this->set('name',$names);

    if(empty($this->data)){
        $this->data= $this->Field->read($fields);
    } 
    else{
        if(($this->Field->save($this->data)))
        {
            $this->Session->setFlash('The field has been updated');
            $this->redirect(array('controller'=>'invoices', 'action'=>'index'));

        }
        }
}

这里是风景

<?php echo $this->Form->create('fields_invoices'); ?>
    <?php foreach ($field as $fields): ?>
    <?php echo $this->Form->Input($fields); ?>
    <?php endforeach ;?>
    <?php echo $this->Form->End('Submit');?>

现在我不确定如何正确编码视图并获取它,以便它将fields 表中的default_variables 打印到input boxes 中。任何帮助将不胜感激

【问题讨论】:

    标签: forms cakephp formhelper


    【解决方案1】:

    您能帮我们调试一下 $fields 数组吗?

    您可以在自动生成的输入字段中指定您想要的内容...

    ie: $this->Form->input('field_name',array('label'=>'随便你叫什么','value'=>'value'));

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 2016-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多