html form methode = post action = URL

时间:2016-06-30 11:17:29

标签: html forms

我创建了一个表单而我的提交按钮不起作用。



<!DOCTYPE HTML>
<html lang="en">

<head>

</head>

<body>


  <div class="container">

    <div class="row">

      <div class="col-lg-8 col-lg-offset-2">


        <form id="contact-form" method="post" action="http://www.example.com/?lang=en&p=send" role="form">

          <div class="messages"></div>

          <div class="controls">
            <!--  Name -->
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label for="form_name">Firstname *</label>
                  <input id="form_name" type="text" name="name" class="form-control" placeholder="Please enter your firstname *" required="required" data-error="Firstname is required.">
                  <div class="help-block with-errors"></div>
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label for="form_lastname">Lastname *</label>
                  <input id="form_lastname" type="text" name="surname" class="form-control" placeholder="Please enter your lastname *" required="required" data-error="Lastname is required.">
                  <div class="help-block with-errors"></div>
                </div>
              </div>
            </div>
            <!--  End Name -->
            <!--  SUBJECT -->
            <div class="row">
              <div class="col-md-8">
                <div class="form-group">
                  <label for="form_subject">Subject *</label>
                  <input id="form_subject" type="text" name="subject" class="form-control" placeholder="Please enter your Subject *" required="required" data-error="Subject is required.">
                  <div class="help-block with-errors"></div>
                </div>
              </div>
            </div>
            <!--  END SUBJECT -->
            <!--  Message -->
            <div class="row">
              <div class="col-md-12">
                <div class="form-group">
                  <label for="form_message">Message *</label>
                  <textarea id="form_message" name="message" class="form-control" placeholder="Message for me *" rows="4" required="required" data-error="Please,leave us a message."></textarea>
                  <div class="help-block with-errors"></div>
                </div>
              </div>
              <div class="col-md-12">
                <input type="submit" class="btn btn-success btn-send" value="Send message">
              </div>
            </div>
            <!--  End Message -->
            <div class="row">
              <div class="col-md-12">
                <p class="text-muted"><strong>*</strong> These fields are required.</p>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>

</body>

</html>
&#13;
&#13;
&#13;

当我把动态部分中的发送文件的相对地址放在工作部分时。 我的路上有可能吗? 我在我的index.php中通过php包含内容部分。我尝试在index.php中打开send.php

谢谢!

1 个答案:

答案 0 :(得分:0)

如果我说得对,你想在同一页面上处理表格的动作。所以你必须将动作设置为:

<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">

在PHP部分中,您必须检查表单是否已提交。如下所示:

<?php    
if(isset($_POST['form_message'])){ //check if form was submitted

}    
?>