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.

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

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能