我在我的網站上有聯繫表單。我希望在提交表單成功提交後,將提交按鈕的文本更改爲「已提交」,甚至可以在提交表單時聲明「提交」。我不確定如何做到這一點,我可以做一個onclick事件,這將改變文本,但不是我想要採取的路由,因爲消息可能無法發送,並且按鈕仍然會提交。更改表單提交按鈕的值以在表單提交後提交
這裏是我的形式
<form method="post" action="contact.php">
<input type="text" name="name" placeholder="Name"><br>
<input type="email" name="email" placeholder="Email"><br>
<textarea rows="8" cols="65" name="message"placeholder="Message"></textarea><br>
<input id="submit" type="submit" name="submit" value="Let's Get In Touch">
</form>
,這裏是我的PHP代碼的html:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Portfolio Website';
$to = '[email protected]';
$subject = 'Message From Personal Site';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
有沒有辦法用我現有的PHP代碼做到這一點?預先感謝您的幫助。