代码之家  ›  专栏  ›  技术社区  ›  Jonathan

PHP-QuickForm作为Get而不是Post提交

  •  1
  • Jonathan  · 技术社区  · 15 年前

    我正试图开始使用PEAR的HTML_QuickForm,但我遇到了一个问题。出于某种原因,我的所有表单数据都是使用GET而不是POST提交的。默认设置应该是POST,我已经尝试过显式设置它。我唯一能弄明白的是,当我简单地调用表单上的display()时,它工作正常。我使用的是静态模板,由于某种原因,当我使用它时,它不能正常工作。下面是我的代码。

    <?php
    include_once 'HTML/QuickForm.php';
    include_once 'HTML/Template/Sigma.php';
    include_once 'HTML/QuickForm/Renderer/ITStatic.php';
    
    $form = new HTML_QuickForm('formtest', 'post');
    $form->addElement('text', 'mytext');
    $form->addRule('mytext', 'This is required', 'required');
    $form->addElement('submit', 'mysubmit', 'This is a submit button');
    
    $tpl = & new HTML_Template_Sigma('.');
    $tpl->loadTemplateFile('template.html');
    $renderer = & new HTML_QuickForm_Renderer_ITStatic($tpl);
    $renderer->setRequiredTemplate('{label}<font color="red" size="1">*</font>');
    $renderer->setErrorTemplate('<font color="red">{error}</font><br />{html}');
    $form->accept($renderer);
    $tpl->show();
    ?>
    
    1 回复  |  直到 15 年前
        1
  •  1
  •   Jonathan    6 年前

    没关系,我几乎立刻意识到了这个问题。我的模板文件如下所示:

    <html>
    <head><title>Test Form</title></head>
    <body>
    <form>
    {formtest_mytext_html}<br />
    {formtest_mytext_label}<br />
    {formtest_mysubmit_html}<br />
    {formtest_mysubmit_label}<br />
    </form>
    </body>
    </html>
    

    问题是,我的表单标签无法知道它应该是POST,所以它总是默认获取。相反,表单标签应该是这样的

    <form {formtest_attributes}>
    

    {formtest_attributes}当然是告诉表单使其自身成为POST的位。