简体   繁体   English

如何选择提交不同的php页面的选项

[英]how to select option to submit different php page

drop down select "sales" go to sales.php, other options selected go to addFund.php... 下拉选择“sales”转到sales.php,选择其他选项转到addFund.php ...

<form name='searform' method='post' action='<?php echo $home;?>addFund.php'>
Search : <input type='text' id='sear' name='sear'> by 
<select id='psel' name='psel' onchange='change()'>
<option value='email'>Email</option>
<option value='name'>Username</option>
<option value='domain'>Domain name</option>
<option value='sales'>Sales</option>
</select>
<input type='submit' name='sub' id='sub' value='Go' onclick='gopage()'>
<input type='submit' name='dir' id='dir' value='Direct'>
</form>

How to submit different pages 如何提交不同的页面

You could use some Javascript nastiness to achieve this with the change() function, but the usual way to do this is to route all requests through a controller and include() the appropriate page. 您可以使用一些Javascript nastiness来使用change()函数来实现这一点,但通常的方法是通过控制器路由所有请求并include()相应的页面。 For example, point your form to action.php , and in that file, do this: 例如,将表单指向action.php ,并在该文件中执行以下操作:

action.php action.php的

<?php

  if (isset($_POST['psel']) && $_POST['psel'] == 'sales') {
    include 'sales.php';
  } else {
    include 'addFund.php';
  }

...or you could just put roughly that code into addFund.php , since you only seem to have one other script that you would want to send requests to. ...或者您可以将该代码粗略地放入addFund.php ,因为您似乎只有另一个您想要发送请求的脚本。

You could do this with javascript: 你可以用javascript做到这一点:

function change(el) {
  if(el.value === 'sales') {
    el.form.action = 'sales.php';
  } else {
    el.form.action = 'addFund.php';
  }
}

Change the onchange to onchange="change(this)" . 将onchange更改为onchange="change(this)" A better way would be to check the variable on serverside and include the right file. 更好的方法是检查服务器端的变量并包含正确的文件。

Change your select to this: 将您的选择更改为:

<select name="vote" onChange="document.forms['searForm'].submit()">

And make your form action go to something like pageChange.php where it returns a different page depending on the $_POST value. 并使您的表单操作转到类似pageChange.php的位置,它返回一个不同的页面,具体取决于$_POST值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM