简体   繁体   English

表单基于值提交到URL

[英]Form Submit to URL based on Value

This may sound weird but i trying to make a form that submit to different page according to the value of database 这听起来可能很奇怪,但是我试图根据数据库的值制作一个提交到不同页面的表单

Database 数据库

| value | etc.Info 
    1
  -----

Code

<form action="?I donno put what to determind them to go?" method="POST">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
<input type="submit" class="btn btn-primary btn-sm" value="Edit"/>
</form>

And my wish is to click the button and go to another page with name upload.php when the value is 1 on database and go to detail.php when the value is 0, any advice will be good and i thank you in advance who all wish to help 我希望单击该按钮,然后在数据库上值为1时转到名称为upload.php的另一页,并在值为0时转到detail.php,任何建议都将是很好的,我在此先感谢您希望对您有所帮助

<form action="anotherpage.php" method="POST">

In anotherpage.php 在anotherpage.php中

$yourhiddenvalue= $_POST['id'];
if($yourhiddenvalue ==0){
//redirect to detail.php
}
if($yourhiddenvalue ==1){
//redirect to upload.php
}

If you know the ID when the page loads you can do 如果您知道页面加载时的ID,可以执行

if($_POST['id'] == 0) {
    $location = "detail.php";
} else {
    $location = "upload.php";
}

You can also do this is a switch statement if there are more than two options. 如果有两个以上的选项,您也可以使用switch语句来执行此操作。

then your form would be 那么您的表格将是

<form action="<?php echo $location; ?>" method="POST">

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

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