如何在文本框中键入某些单词时自动发送表单-PHP


how to automatically send a form when certain word is typed in a textbox-PHP?

如果输入了单词".xml",则无需按提交按钮即可发送表单?

是的,但这不是PHP的问题。为此,你需要JavaScript/jQuery。

http://api.jquery.com/keypress/

正如Forien所说,这可以在JS或jQuery中完成。

这是一个jQuery解决方案,可以让您走上正确的轨道。不确定它是否有效,但可以尝试一下:

$(document).ready(function(){
    $( "#textf" ).keypress(function() {
        if($("#textf").contains(".xml")){
             $( "#testform" ).submit();
        }
    });
});

你不想在 PHP 中执行此操作,但你可以使用键启动侦听器,如下所示:

$(document).on("keyup", "#watch", function() {
  // console.log($(this).val());
  if ($(this).val() === ".xml") {
    $('form#form-watch').submit();
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form id="form-watch">
  <input type="text" id="watch" />
</form>