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

问题描述 投票:0回答:1

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

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

下面是我的渲染表单脚本

 // 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!<>,;?=+()@#"°{}_$%:'
            ),
             array(
                'type' => 'text',
                'label' => $this->l('Ticket No'),
                'name' => 'ticket_no',
                'required' => true,
                'col' => '4',
                'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
            ),
            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;,;?   =+()@#"°{}_$%:'
            ))
        ));
php prestashop prestashop-1.6 prestashop-1.7 prestashop-1.5
1个回答
0
投票

使用

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

© www.soinside.com 2019 - 2024. All rights reserved.