表单操作-错误404-找不到


Forms action - Error 404 - not found

我正在尝试使用表单和PHP发送电子邮件。当我点击发送按钮时,我得到了错误发生错误:404-找不到。submit.php文件与网页位于同一目录中。为什么它找不到submit.php。我的html代码。

<form action="submit.php" id="form1" method="post">
<fieldset>              
    <label class="input">Date:<span><span><input type="text" id="datepicker" value=""/></span></span></label>
    <label class="input">Enter Your Name:<span><span><input name="name"/></span></span></label>
    <label class="input">Enter Your Email:<span><span><input name="email"/></span></span></label>
    <label class="input">Subject:<span><span><input name="subject"/></span></span></label>
    <label class="text">Enter Your Message:<span><span><textarea name="comment" cols="0" rows="0"></textarea></span></span></label>
    <label class="input">Enter Code:<img src="php/captcha.php"><span><span><input type="text" name="vercode" /></span></span></label>
    <label class="butt"><a href="javascript:document.getElementById('form1').reset()" class="button"><strong><b>clear</b></strong></a>
    <a href="javascript:document.getElementById('form1').submit()" class="button"><strong><b>send</b></strong></a></label>
</fieldset>

当使用<a>的作为表单提交按钮时,我建议使用JavaScript函数并将其放在锚的onclick中。像这样:

function doSubmit(form_name) {
  // check if the object exists
  if (document.getElementById(form_name)) {
    // submit the form
    document.getElementById(form_name).submit();
  }
  // prevent the link from clicking
  return false;
}
<a href="#" onclick="return doSubmit('form1');" class="button"><strong><b>send</b></strong></a>

重置按钮也可以这样做。

通过这种方式,您永远不会将浏览器导航到"javascript:…etc."位置(该位置不存在)。我不确定这里是否是这样,但作为最佳实践建议。:)