2011-02-10 52 views
0

如何更改此表單的動作?目前,它的帖子到index.php文件(我使用php-form-builder-class) 我使用了一個switch語句中的index.php如下:更改表單的動作

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

    default: 
    echo "Hello"; 
} 

所以在SITE /用戶/動作=新的(或用戶/ index.php?action = new)表單顯示出來。我希望表單提交本身,而不是index.php的(即行動=「」)

形式如下(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(); 
+0

該類的文檔相當吸引人。也許你可以在初始的setAttributes()調用中添加一個'action'參數。 – 2011-02-10 14:11:15

回答

2

由$形式使用的行動存儲在Attributes數組中,因此您可以通過在setAttributes數組中傳遞一個新值來覆蓋默認值。

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