开发者

Changing action of a form

How can I change the action of this form? It currently posts to index.php (I'm using php-form-builder-class) I'm 开发者_如何转开发using a switch statement in index.php as follows:

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

    default:
    echo "Hello";
}

So in SITE/user/?action=new (or user/index.php?action=new) the form shows up. I want the form to submit to itself, and not index.php (i.e action="")

The form is as follows (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();


The action used by the $form is stored in the Attributes array, so you can override the default by passing a new value in the setAttributes array.

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜