dtiu94034 2015-04-26 09:38 采纳率: 0%
浏览 88

在Laravel中从同一网页发布两个表单

I am creating a one page website using laravel where I have a login form and a registration form on the same page.

I wish to route them to their respective controller functions, say, AccessController@login and AccessController@register respectively. How can I achieve this, when for both the forms the route would be:

Route::post('/', 'ControllerName@function')
  • 写回答

2条回答 默认 最新

  • dqys98341 2015-04-26 09:44
    关注

    It's generally a bad idea, but you can achieve what you want by doing this:

    1. Add <input type="hidden" name="action" value="register"> and <input type="hidden" name="action" value="login"> to signup and login forms accordingly

    2. In controller method check which form was submitted:

      $action = Input::get('action');
    
      // handle the register request
      if ($action === 'register') {
          return $this->register();
    
      // handle the login request
      } elseif ($action === 'login') {
          return $this->login();
    
      } else {
          throw new Exception("Unknown action");
      }
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!