Home > Backend Development > PHP Tutorial > php实现表单多按钮提交action的处理方法_PHP

php实现表单多按钮提交action的处理方法_PHP

WBOY
Release: 2016-05-29 11:48:42
Original
1309 people have browsed it

表单内有两个提交按钮,要实现当点击不同的提交按钮时,分别进行两个不同的处理过程,在这里有实现表单多按钮提交action的处理方法分享给大家。

用PHP判断,一个表单两个按钮,按钮的name属性设为相同,但值设为不同,表单提交后,只需要判断提交上来的值就可以转到不同的处理过程去,这个方法比较合理,适合多个按钮在一个表单里。

PHP方法,代码如下:

<&#63;php  
 echo "$sub<br>\n";  
 if ("s1"==$sub)  
 {  
  ...  
 }  
 else if ("s2"==$sub)  
 {  
  ...  
 }  
 &#63;>  
 <html>  
 <head><title></title></head>  
 <body>  
 <form action="<&#63;php print("$PHP_SELF"); &#63;>" method="get">  
 <input type="submit" name="sub" value="s1">  
 <input type="submit" name="sub" value="s2">  
 </form>  
 </body>  
 </html>  
 &#63;> 
Copy after login

 以上就是php实现表单多按钮提交action的方法,希望对大家的学习有所帮助。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template