如果复选框为check,则运行Mailchimp Code
If checkbox is check run Mailchimp Code
我有一个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"/>
相关文章:
- 如何使用phaser使html5游戏在移动设备浏览器上运行
- 使用压缩的JavaScript文件(不是运行时压缩)
- Javascript运行php文件,然后下载文件
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 我已经创建了一个jquery转盘,并使用if条件来运行和停止转盘
- Angularjs代码未在匿名函数中运行
- jquery设置为使用参数运行
- 如何根据时间运行不同的脚本
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- 将文本框链接到由按钮运行的javascript公式
- 为什么不是't运行此Javascript的Chrome
- ng应用程序使脚本无限运行
- 如何在运行时在angular 2中加载外部js脚本
- 与运行长作业(javascript,node.js)的第三方API同步的最佳实践
- JavaScript错误:Microsoft JScript运行时错误:应为对象
- 在终端中运行 JavaScript 时(使用 rhino),如何使用 print() 函数在一行中打印
- 如何使用JS/nightwatchjs并行运行多个测试
- 茉莉花宝石-耙茉莉花:ci dons't运行测试
- 我的HTML按钮没有在Javascript中运行
- 如果复选框为check,则运行Mailchimp Code