如果复选框为check,则运行Mailchimp Code

If checkbox is check run Mailchimp Code

本文关键字:运行 Mailchimp Code 复选框 check 如果      更新时间:2023-09-26

我有一个PHP联系人表单,其中有一个复选框,用户在注册时可以选择是否订阅时事通讯,但是我想使用Mailchimp来捕获电子邮件地址并放入列表中。此外,我使用的javascript一旦提交的形式。如果复选框被选中,窗体和mailchimp中的代码将同时执行,我如何创建一个条件?

这是我的表格

<form role="form" id="feedbackForm">
      <div class="form-group">
        <input type="text" class="form-control" id="first_name" name="first_name" placeholder="First Name">
        <span class="help-block" style="display: none;">Please enter your name.</span>
      </div>
      <div class="form-group">
        <input type="text" class="form-control" id="last_name" name="last_name" placeholder="Last Name">
        <span class="help-block" style="display: none;">Please enter your name.</span>
      </div>
      <div class="form-group">
        <input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
        <span class="help-block" style="display: none;">Please enter a valid e-mail address.</span>
      </div>
      <div class="form-group">
        <input type="text" class="form-control" id="company_name" name="company_name" placeholder="Company">
        <span class="help-block" style="display: none;">Please enter your name.</span>
      </div>
      <div class="form-group">
        <textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
        <span class="help-block" style="display: none;">Please enter a message.</span>
      </div>
      <div class="form-group">
        <label for="selectbasic">How did you hear about us?</label>
            <select id="selectbasic" name="selectbasic" class="form-control">
                <option>Select</option>
                <option>Search engine</option>
                <option>Microsoft DPE</option>
                <option>Microsoft event</option>
                <option>Social media</option>
                <option>Word of mouth</option>
                <option>Other</option>
            </select>
        </div>
      <img id="captcha" src="library/vender/securimage/securimage_show.php" alt="CAPTCHA Image" />
      <a href="#" onclick="document.getElementById('captcha').src = 'library/vender/securimage/securimage_show.php?' + Math.random(); return false" class="btn btn-info btn-sm">Show a Different Image</a><br/>
      <div class="form-group" style="margin-top: 10px;">
        <input type="text" class="form-control" name="captcha_code" id="captcha_code" placeholder="For security, please enter the code displayed in the box." />
        <span class="help-block" style="display: none;">Please enter the code displayed within the image.</span>
      </div>
      <div class="checkbox">
        <label>
           <input type="checkbox" id="emailUpdates" name="emailUpdates" value="Yes">  
            Please keep me informed of product updates and news
        </label>
      </div>
      <span class="help-block" style="display: none;">Please enter a the security code.</span>
      <button type="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style="display: block; margin-top: 10px;">Send Feedback</button>
    </form>

复选框代码-

      <div class="checkbox">
        <label>
           <input type="checkbox" id="emailUpdates" name="emailUpdates" value="Yes">  
            Please keep me informed of product updates and news
        </label>
      </div>
复选框脚本
<?php
   if ($_POST['emailUpdates'] == 'Yes') {
     //EXECUTE MAILCHIMP CODE
   }
    ?>

将复选框的value属性保留为空,如果选中,它将提交on的值,否则它将不提交任何值

  <?php
  if (isset($_POST['emailUpdates'])) {
    //EXECUTE MAILCHIMP CODE
  }
  ?>

  <input type="checkbox" id="emailUpdates" name="emailUpdates"/>