开发者

PHP - QuickForm Submits as Get Rather Than 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();
?>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜