dongyi1111 2015-08-23 23:00
浏览 38

prestashop通过ajax生成一个带有renderform的新表单内容

I created a button when clicked triggers the renderForm function with prestashop that is supposed to generate the form via ajax.But it doesn't seem to work. Can anyone please help me or point me in the right direction because i'm new with prestashop ? in the catproduct.php

public function generateform(){

$html = '<a href="#" class="displayForm">Click me</a>
         <div id="myFormm"></div>
        <script type="text/javascript">
        $( ".displayForm" ).click(function() {
            $.ajax({
              url: "'._MODULE_DIR_.$this->name.'/ajax.php",
              context: document.body,
                })
                .done(function(data) {
                $( "#myFormm" ).html( data );
                alert( "Load was performed." );
            });


        })
    </script>';



return $html;

}


public function renderForm()
{
    $fields_form = array(
        'form' => array(
            'legend' => array(
                'title' => $this->l('Add new category'),
                'icon' => 'icon-cogs'
            ),
            'input' => array(
                array(
                    'type' => 'text',
                    'label' => $this->l('FCI'),
                    'name' => 'FCI',
            ),
            ),

            'submit' => array(
                'title' => $this->l('Save')
            )
        ),
    );
    $helper = new HelperForm();
    $helper->show_toolbar = false;
    $helper->table = $this->table;
    $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
    $helper->default_form_language = $lang->id;
    $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
    $this->fields_form = array();

    $helper->identifier = $this->identifier;
    $helper->submit_action = 'submitCatForm';
    $helper->fields_value['FCI'] = 'ddddd';
    $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='
    .$this->tab.'&module_name='.$this->name;
    $helper->token = Tools::getAdminTokenLite('AdminModules');

    return $helper->generateForm(array($fields_form));
}

the ajax.php file (the ajax file call the renderForm() function to create new form):

require_once(dirname(__FILE__).'../../../config/config.inc.php');
require_once(dirname(__FILE__).'../../../init.php');

include_once('catproduct.php'); 
$module = new catproduct(); 
echo $module->renderForm();
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法