简体   繁体   English

表格未提交

[英]Form being not submitted

I have a simple html form that should be using POST method to submit the form and it will send form contents on mail.php to send email. 我有一个简单的html表单,应该使用POST方法提交表单,它将在mail.php上发送表单内容以发送电子邮件。 I have verified the php mail functionality working on server using the following code: 我已经使用以下代码验证了服务器上的php邮件功能:

  $headers = 'From: webmaster@example.com'; mail('myemail@mail.com', 'test email yo', 'This is a test email message', $headers, '-fwebmaster@example.com');

the PHP code I'm using to send the mail is as follows: 我用来发送邮件的PHP代码如下:

mail('myemail@mail.com', $_POST['name'], $_POST['email'], $_POST['phone'], $_POST['message']);

the html form that should be sending the info is this: 应该发送信息的html表单是这样的:

<form id="contact-form" class="contact-form" method="post" action="mail.php">
    <div class="success-message">Contact form submitted.</div>
    <div class="coll-1">
        <p class="mbot3">Name*</p>
        <label class="name">
            <input type="text" placeholder="" data-constraints="@Required @JustLetters" name="name"/>
            <span class="empty-message">*This field is required.</span>
            <span class="error-message">*This is not a valid name.</span>
        </label>
    </div>
    <div class="coll-2">
        <p class="mbot3">E-mail*</p>
        <label class="email">
            <input type="text" placeholder="" data-constraints="@Required @Email" name="email"/>
            <span class="empty-message">*This field is required.</span>
            <span class="error-message">*This is not a valid email.</span>
        </label>
     </div>
     <div class="coll-3">
         <p class="mbot3">Phone</p>
         <label class="phone">
             <input type="text" placeholder="" data-constraints="@JustNumbers" name="phone"/>
             <span class="empty-message">*This field is required.</span>
             <span class="error-message">*This is not a valid phone.</span>
         </label>
      </div>
      <label class="message">
          <span class="mbot3">Message*</span>
          <textarea placeholder="" data-constraints="@Required @Length(min=20,max=999999)" name="message"></textarea>
          <span class="empty-message">*This field is required.</span>
          <span class="error-message">*The message is too short.</span>
       </label>
   <div>
      <a href="#" data-type="submit" class="btn-link btn-link1"><img src="img/arrow1.png" alt="">submit</a>
      <p class="req">* Required fields</p>
   </div>
</form>

I can't get the contents of the form to come through in the email, I'm assuming possibly wrongly that the issue is with the form and it's ability to POST the info to php? 我无法在电子邮件中获取表单的内容,我可能错误地认为问题出在表单上,​​并且可以将信息发布到php?

This code is from a premade template I did not write it myself. 这段代码来自一个我自己没有编写的预制模板。

Edit: As suggested I added the name attributes however that has not fixed the issue. 编辑:按照建议,我添加了名称属性,但是并没有解决问题。 Updated HTML to reflect current code. 更新了HTML以反映当前代码。

Edit2: Have solved problem, I had to remove id="contact-form" not sure what was associated with this that was preventing the form submitting but that did it. Edit2:解决了问题,我不得不删除id =“ contact-form”,但不确定与此相关的是什么阻止了表单提交,但是做到了。 From there I took the styles from the original form and added them to a new id that I replaced it with. 从那里,我从原始表单中获取样式,并将其添加到替换为的新ID中。

You missed the name to the input and textarea field 您错过了输入和文本字段的名称

<input type="text" placeholder="" data-constraints="@Required @JustLetters"  name = "name"/>

The name attribute should have the same name as you are receiving from $_POST['name'] name属性名称$ _POST ['name']收到的名称相同

Check these fields on your HTML code, 检查您的HTML代码中的这些字段,

<input type="text" placeholder="" data-constraints="@Required @JustLetters" />
<input type="text" placeholder="" data-constraints="@Required @Email" />
<input type="text" placeholder="" data-constraints="@JustNumbers"/>
<textarea placeholder="" data-constraints="@Required @Length(min=20,max=999999)"></textarea>

And replace them with following code, you missed to add name attribute, name attribute used to reference form data after you submit the form. 并用以下代码替换它们,您错过了添加name属性,即提交表单后用于引用表单数据的name属性。

<input type="text" name="name" placeholder="" data-constraints="@Required @JustLetters" />
<input type="text" name="email" placeholder="" data-constraints="@Required @Email" />
<input type="text" name="phone" placeholder="" data-constraints="@JustNumbers"/>
<textarea name="message" placeholder="" data-constraints="@Required @Length(min=20,max=999999)"></textarea>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM