改变表格的行动

时间:2011-02-10 14:04:36

标签: php validation forms

如何更改此表单的操作?它目前发布到index.php(我正在使用php-form-builder-class) 我在index.php中使用switch语句,如下所示:

switch ($_GET['action'])
{
    case 'new':  
       require_once USER_ROOT . 'new_thread.php';
       echo "We are in user new";
    break;

    default:
    echo "Hello";
}

因此,在SITE / user /?action = new(或user / index.php?action = new)中,表单会显示出来。我希望表单提交给自己,而不是index.php(即action =“”)

表格如下(new_thread.php):

$form = new form("new_thread_form");

$form->setAttributes(array(
     "width" => 400,
     "jsIncludesPath" => "/lib/php-form-builder-class/includes"
));

if($form->validate()) {
   echo "Your form has validated";
}    
else {
   echo "It has not validated";
}    

$form->addHidden("cmd", "submit_0");
$form->addTextbox("Title:", "thread_title", "", array("required" => 1));

$form->addTextarea("Content:", "thread_content", "", array("required" => 1));
$form->addTextbox("Tags:", "thread_tags", "", array("required" => 1));


$form->addButton();
$form->render();

1 个答案:

答案 0 :(得分:2)

$ form使用的操作存储在Attributes数组中,因此您可以通过在setAttributes数组中传递新值来覆盖默认值。

$form->setAttributes(array(
 "width" => 400,
 "jsIncludesPath" => "/lib/php-form-builder-class/includes",
 "action" => ""
));