在PRESTASHOP 1.6.3中使用HelperForm时,向未向用户公开的字段添加隐藏值或插入值

时间:2016-04-25 11:43:23

标签: prestashop prestashop-1.6 prestashop-1.5 prestashop-1.7

在PRESTASHOP 1.6.3中使用HelperForm类时,如何向未向用户公开的字段添加隐藏值或插入值,例如date_add和date_upd

我创建了一个新模块,现在我的表中有两个字段需要在新添加发生时以及用户完成更新时插入,但是当我在PRESTASHOP中使用HelperForm类时如何执行此操作< / p>

下面是我的渲染表单脚本

 // This  form is populated  when  add or edit is clicked
 public function renderForm()
  {
    $years        = Tools::dateYears();
    $months       = Tools::dateMonths();
    $days         = Tools::dateDays();
    $ticketSeries = Winners::getTicketSeries();
    $prdtCategory = Winners::getProductCategory();
    $nationality  = Winners::getNationality();
    $this->fields_form = array(
        'tinymce' => true,
        'legend' => array(
            'title' => $this->l('Configure your Winner'),
            'icon' => 'icon-user'
        ),          
        'input' => array(
             array(
                'type' => 'text',
                'label' => $this->l('Name'),
                'name' => 'name',
                'required' => true,
                'col' => '4',
                'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()@#"°{}_$%:'
            ),
             array(
                'type' => 'text',
                'label' => $this->l('Ticket No'),
                'name' => 'ticket_no',
                'required' => true,
                'col' => '4',
                'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()@#"°{}_$%:'
            ),
            array(
                'type' => 'select',
                'label' => $this->l('Ticket Series'),
                'name' => 'series',
                'required' => true,
                'options' => array(
                    'query' => $ticketSeries,
                    'id' => 'ticket_series_name',
                    'name' => 'ticket_series_name'
                ),
                'col' => '4',
                'hint' => array(
                    $this->l('The ticket series of each draw !!.')
                )
            ),
            array(
                'type' => 'select',
                'label' => $this->l('Category'),
                'name' => 'category',
                'required' => true,
                'options' => array(
                    'query' => $prdtCategory,
                    'id' => 'name',
                    'name' => 'name'
                ),
                'col' => '4',
                'hint' => array(
                    $this->l('Product Category.')
                )
            ),

            array(
                'type' => 'date',
                'label' => $this->l('Draw Date:'),
                'name' => 'draw_date',
                'size' => 10,
                'required' => true,
                'desc' => $this->l('The draw date of this series'),
            ),
                array(
                'type' => 'select',
                'label' => $this->l('Nationality'),
                'name' => 'nationality',
                'required' => true,
                'options' => array(
                    'query' => $nationality,
                    'id' => 'name',
                    'name' => 'name'
                ),
                'col' => '4',
                'hint' => array(
                    $this->l('Nationality the winner Belongs .')
                )
            ),

            array(
                'type' => 'textarea',
                'label' => $this->l('Testimonial'),
                'name' => 'testimonial',
                'required' => true,
                'autoload_rte' => true,
                'rows' => 7,
                'cols' => 40,
                'hint' => $this->l('Invalid characters:').' <>;=#{}'
            ), //  add  tag  'autoload_rte' => true, 'lang' => true, --> lang i removed 
               // since the editor value did not submit  editor                  
        )
    );

    //d(Tools::getIsset('update'));

    if (Tools::getIsset('add') )
        $this->fields_form = array_merge(array(
             'input' => array(
             array(
                'type' => 'text',
                'label' => $this->l('Add Date'),
                'name' => 'date_add',                   
                'col' => '4',
                'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()@#"°{}_$%:'
            ))
        ));
    if (Tools::getIsset('update'))
        $this->fields_form = array_merge(array(
             'input' => array(
             array(
                'type' => 'text',
                'label' => $this->l('Update Date'),
                'name' => 'date_upd',                   
                'col' => '4',
                'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?   =+()@#"°{}_$%:'
            ))
        ));

    $this->fields_form['submit'] = array(
        'title' => $this->l('Save'),
    );

    $this->addJqueryUI('ui.datepicker');
    return parent::renderForm();
 }

我尝试了类似下面但没有用的东西

    if (Tools::getIsset('add') )
        $this->fields_form = array_merge(array(
             'input' => array(
             array(
                'type' => 'text',
                'label' => $this->l('Add Date'),
                'name' => 'date_add',                   
                'col' => '4',
                'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()@#"°{}_$%:'
            ))
        ));
    if (Tools::getIsset('update'))
        $this->fields_form = array_merge(array(
             'input' => array(
             array(
                'type' => 'text',
                'label' => $this->l('Update Date'),
                'name' => 'date_upd',                   
                'col' => '4',
                'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?   =+()@#"°{}_$%:'
            ))
        ));

1 个答案:

答案 0 :(得分:0)

使用'type' => 'hidden'并提供值,例如'value' => date("Y-m-d H:i:s")