简体   繁体   English

联络人表单/邮件正文中的php变量

[英]Php variable in contact form / message body

I have a contact form that is only passing over some of the form fields and i wondered if anyone can help as to why? 我有一个仅在某些表单字段中传递的联系表单,我想知道是否有人可以提供帮助?

The html form is as follows: html格式如下:

            <form enctype="multipart/form-data" method="post" action="referral.php" onsubmit="return submitForm()">
      <fieldset>
          <div class="field">
            <input name="name" id="name" type="text" class="validate" placeholder="Your Name" />
            <span class="form-msg" id="name-error">Please add your name</span>
          </div>
            <div class="field here-for-next-until">
              <input name="email" id="email" type="text" class="validate" placeholder="Your E-mail" class="text-input validate" />
              <span class="form-msg" id="email-error">Please add your e-mail address</span>
            </div>
            <div class="field">
              <input name="phone" id="phone" type="text" placeholder="Your Phone Number" class="text-input validate" />
              <span id="phone-error" class="form-msg" >Please add your phone number</span>
            </div>                        
            <div class="area here-for-next-until">
              <textarea name="message" id="message" class="text-input validate" placeholder="Introduce Yourself"></textarea><br/>
              <span class="form-msg" id="email-error">Please add an introduction to yourself</span>
              <input type="text" id="cap_val" name="cap_val" class="code validate" placeholder="Enter Code From Right"/>
              <img src="bin/captcha.php" id="cap"/><img src="images/refresh.jpg" id="cap-refresh" onclick="change_captcha()"/><br/>
            <span id="captcha-error" class="form-msg" >Please add the above code</span>
            <div class="clear here-for-next-until"></div>
          </div>
    </div>

   <div class="flt-lt w420">
    <h2 class="subheader">Client</h2>
          <div class="field">
            <input name="referralsname" id="name" type="text" class="validate" placeholder="Name" />
            <span class="form-msg" id="name-error">Please add your referrals name</span>
          </div>
            <div class="field here-for-next-until">
              <input name="referralsemail" id="email" type="text" class="validate" placeholder="E-mail address" class="text-input validate" />
              <span class="form-msg" id="email-error">Please add your referrals e-mail address</span>
            </div>
            <div class="field">
              <input name="referralsphone" id="phone" type="text" placeholder="Phone Number" class="text-input validate" />
              <span id="phone-error" class="form-msg" >Please add your referrals phone number</span>
            </div>                        
            <div class="area here-for-next-until">
              <textarea name="referralsmessage" id="message" class="text-input validate" placeholder="Introduce Yourself"></textarea><br/>
              <span class="form-msg" id="email-error">Please add an introduction to yourself</span>
            <div class="clear here-for-next-until"></div>
                        <div id="submit-holder">
              <input class="submit" type="submit" value="Submit"/>
              <input id="reset" class="submit" type="reset" value="Reset"/>
            </div>
          </div>
      </fieldset>
    </form>

Basically this is two very similar contact forms side by side that share a submit button 基本上这是两个非常相似的共享提交按钮的联系方式

When posted it goes to this: 发布后转到:

$owner_email = 'myemail.co.uk';
  $subject = A message from your site visitor ' . $_POST["name"];

  $messageBody = "\nVisitor: " . $_POST["name"] . "\n";
  $messageBody .= "Email Address: " . $_POST['email'] . "\n";
  $messageBody .= "Phone Number: " . $_POST['phone'] . "\n";
  $messageBody .= "Message: " . $_POST['message'] . "\n";

  $messageBody = "\nVisitor: " . $_POST["referralsname"] . "\n";
  $messageBody .= "Email Address: " . $_POST['referralsemail'] . "\n";
  $messageBody .= "Phone Number: " . $_POST['referralsphone'] . "\n";
  $messageBody .= "Message: " . $_POST['referralsmessage'] . "\n";

However when I submit the form I onyl get one set of details (the first 4 $messageBody) 但是,当我提交表单时,onyl会得到一组详细信息(前四个$ messageBody)

Any help anyone could offer would be greatly appreciated. 任何人都可以提供的任何帮助将不胜感激。

Thanks again 再次感谢

David 大卫

Change: 更改:

$messageBody = "\\nVisitor: " . $_POST["referralsname"] . "\\n";

To: 至:

$messageBody .= "\\nVisitor: " . $_POST["referralsname"] . "\\n";

( .= instead of = , you are re-assigning value to $messageBody instead of chaining it to $messageBody) 。=而不是= ,您是将值重新分配给$ messageBody而不是将其链接到$ messageBody)

if i had to guess, i would say it is because you are repeating the IDs. 如果我不得不猜测,我会说这是因为您正在重复ID。 In HTML element IDs have to be unique. 在HTML中,元素ID必须唯一。 make all IDs match your "name" values. 使所有ID与您的“名称”值匹配。 im referring to 我指的是

<input name="phone" id="phone"....
<input name="referralsphone" id="phone"....

change all these cases to: 将所有这些情况更改为:

<input name="phone" id="phone"....
<input name="referralsphone" id="referralsphone"....

I would also suggest checking the contents of POST. 我也建议检查POST的内容。 this question shows how Echo an $_POST in PHP 这个问题说明如何在PHP中回显$ _POST

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

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