根据html中的用户表单选择重定向到相关网页

时间:2019-01-30 16:59:24

标签: html laravel

我一直在与laravel合作。我在下面创建了表格。我希望用户根据他们的选择将他们定向到我已经创建的特定网页(为了更好地理解,请检查我在代码()中的注释)。路由还可以,但我需要表格帮助。如果可能的话,我只需要使用html(而不是javascript)需要帮助。我的代码如下。问题在于,表单操作将为每个选择用户重定向到/ research。

<html lang="en">
<head>

    <meta charset="UTF-8">

    <title>Please choose department</title>
</head>
<body>

<form method="post" action="/research" id="tmima">

  {{csrf_field()}}

    Select:<br>

<select name="Department" id="dpt">
    <option value="0" selected="selection">Select</option>
    <option value="geo">Geology</option> <!--should place /geology page link-->
    <option value="phs">Physics</option> <!--should place /physics page link-->
    <option value="chm">Chemistry</option> <!--should place /chemistry page link-->

</select>

<input type="submit" value="Αναζήτηση Στοιχείων Φοίτησης">

</form>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

我认为您可以在控制器中执行以下操作:

if (request('Department) == 'geo') {
    return view ('/geology);
} else if  (request('Department) == 'phs') {
    return view ('/psychology);
} else if  (request('Department) == 'chm') {
    return view ('/chemistry);
} else {
    redirect->back();
}