2014-02-12 35 views
1

我想创建一个按钮,提交表单然后重定向到另一个页面。CakePHP提交表单,然后重定向不工作

$('#saveApp').click(function() { 
     event.preventDefault(); 
     $("form[id='CustomerSaveForm']").submit(); // use the native submit method of the form element 
     window.location.href = "<?php echo EWConfig::$URL?>/ExpressWay/ProgramApplications/sales/residence"; 

     return true; 
    }); 

这将重定向而不是提交表单虽然注释掉event.preventDefault()却反其道而行之。

+1

任何理由不从服务器端重定向? –

+0

它只在这个按钮上点击重定向。另一个按钮提交表单并且不重定向。所以我不认为服务器端是最好的选择。 – Subie

+0

你可以使用'ajax'然后''.post(...)'使用'done'事件来确定何时重定向(有助于排序验证等),更多信息在这里https://api.jquery。 com/jQuery.post/ –

回答

0

使用服务器端解决方案结束。

查看

echo $this->Form->button('Save and Redirect', array('name' => 'data[redirect]')); 

控制器

if(!is_null($this->request->data('redirect'))){ 
    $this->redirect(array('controller' => 'Program', 'action' => 'index')); 
}