php 使用php取消按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4553714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 13:26:11  来源:igfitidea点击:

cancel button using php

php

提问by Maerlyn

I have a form,if users clicks cancel with value or w/o value in the textfield it should redirect.

我有一个表单,如果用户在文本字段中单击带有值或不带值的取消,它应该重定向。

Now w/o entering value it is working.If users enters it is getting into db.

现在没有输入值它正在工作。如果用户输入它正在进入数据库。

I tried all js scripts but still not working

我尝试了所有 js 脚本,但仍然无法正常工作

http://pastebin.com/qYLVrMC7

http://pastebin.com/qYLVrMC7

Thanks in advance.

提前致谢。

回答by macino

Why redirec? Should cancel work as canceling the actual action and getting back to previous one? I thing that history.back() should be suffcient in js. Or window.close() if the form is opened in new window. But to make this happend you should make cancel a regular button, not a submit.

为什么要重定向?取消是否应该像取消实际操作并返回上一个操作一样工作?我认为 history.back() 在 js 中应该足够了。或者 window.close() 如果表单在新窗口中打开。但是要做到这一点,您应该使取消成为常规按钮,而不是提交。

Something like this:<input type="button" ... value="Cancel" onclick="history.back();" />

像这样的东西:<input type="button" ... value="Cancel" onclick="history.back();" />

回答by IcePhenom

Try this and change redirectpage to your redirectpage.

试试这个并将重定向页面更改为您的重定向页面。

<input type="button" value="cancel" onClick="document.location.href='http://www.redirectpage.com';" />

<input type="button" value="cancel" onClick="document.location.href='http://www.redirectpage.com';" />

回答by trickwallett

whenever you have an <input type="submit">think of this as just another field value you can check against in your code. e.g. try this:

每当您<input type="submit">认为这只是另一个字段值时,您可以在代码中进行检查。例如试试这个:

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="GET">
<input type="submit" name="foo" value="submit">
<input type="submit" name="foo" value="cancel">
</form> 

<?php 
//validation removed..

if ($_GET['foo'] == 'submit')
{

//do snazzy stuff
print('submit pressed')

}

if ($_GET['foo']) == 'cancel')
{

//do snazzy stuff
print('cancel pressed')



}


?>

hope this helps?

希望这可以帮助?

回答by Maerlyn

You should emphasize the default (submit) action versus the secondary one (cancel). Make submit a regular submit button, cancel a link to the previous page.

您应该强调默认(提交)操作与次要操作(取消)。使提交常规提交按钮,取消到上一页的链接。