将表单值传入PHP而不提交表单

passing form value into php without submitting the form

本文关键字:表单 提交 值传 PHP      更新时间:2023-09-26

我正在建立一个一步一步的形式。第一步,人们输入他们的电子邮箱。然后在他们点击下一步之后,它会从数据库中获得安全问题。

这就是问题所在,是否有可能从数据库中获取数据而不提交from?我发现人们使用AJAX。我是新手。就像我在这里有第一步代码:

<div>
step 1
<input type='text' name='email' id='email' maxlength="50" />
nextstepbutton goes here
</div>

,这是第二步代码:

<div>
step 2
<label><?php echo getSecurityQuestion($emailvalue) ?></label>
</div>

如何将'email'的值传递给$emailvalue

给下一个按钮一个id。如果你用的是jquery你可以在

这一行做点什么
$('#next-button').click(function () {
  $.get('filename.php', { action: 'get_security_question', email: $('#email').val() }, function (data) {
    $('#security_question').val(data['message']);
  });
});
PHP中的

比如

if ($_GET['action'] === 'get_security_question') return "Here's your question for {$_GET['email']}.";

这是非常模糊的,只是一个大致的轮廓,但应该让你知道它是如何工作的

你可以不使用表单,但必须使用AJAX,例如:

<input type="text" name="email" id="email" maxLength="50" />
<input type="button" value="Send" onClick="submitEmail()" />

你需要一个JS函数:

function submitEmail(){
  var emailAdd = document.getElementByID("email").value ;
  // here you would hook into whatever ajax httprequest method you prefer
}