dqrb4228 2009-10-26 04:53
浏览 48
已采纳

PHP - QuickForm提交Get而不是Post

I am trying to get started with PEAR's HTML_QuickForm but I'm having a problem. For some reason all of my form data is being submitted with GET and not POST. The default is supposed to be POST and I've tried setting it explicitly. The only thing I've been able to figure out is that when I simply call display() on the form it works correctly. I'm using a static template and for some reason when I use that it doesn't work correctly. My code is presented below.

<?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条回答 默认 最新

  • dongli7236 2009-10-26 05:04
    关注

    Nevermind, I almost immediately realized the problem. My template file looked like this:

    <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>
    

    The problem was that my form tag had no way to know that it was supposed to be POST so it always defaulted to GET. Instead the form tag should have looked like this

    <form {formtest_attributes}>
    

    The {formtest_attributes} of course being the bit that tells the form to make itself POST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?