我正在尝试发布用户在 Mailchimp 表单中输入注册的名称(名称值为 FNAME
)以显示在我的自定义感谢页面中(例如“谢谢 NAME HERE
,”) 。除了看到使用 *|FNAME|*
之外,我还没有看到如何使用 Mailchimp 的文档来做到这一点这对我想做的事情不起作用,并意识到最好通过 <?php echo $_POST["FNAME"]; ?>
发布我已将其包含在我的 thankyou.html
中它独立于表单所在位置 ( index.html
) 和 PHP 文件 ( store-address.php
)。但是,我似乎无法将所有内容结合在一起来实际打印输入的名称,并且想知道我是否做错了什么。如有任何帮助,我们将不胜感激。
为了澄清一个例子.. Suzy 在我的 mailchimp 表单上注册并单击“提交”,然后我的感谢页面弹出来说“谢谢 Suzy”。本质上,需要读取用户在输入字段中输入的内容,然后再次输出以感谢他们的输入。任何解决方案都很棒!
index.html(表单)
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="get" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" novalidate>
<div class="mc-field-group">
<input type="text" value="" name="FNAME" class="" id="mce-FNAME" placeholder="Name">
</div>
<div class="mc-field-group">
<input type="email" value="" name="email" class="required email" id="mce-EMAIL" placeholder="Email address">
</div>
<div class="clear"></div>
<div class="mc-field-group">
<input type="text" value="" name="MMERGE2" class="" id="mce-MMERGE2" placeholder="Zip Code">
</div>
<div class="mc-field-group">
<label for="mce-MMERGE3" class="believeBecause">I believe because:</label>
<select name="MMERGE3" class="dropdown" id="mce-MMERGE3">
<option value="" class="label"></option>
<option value="I am a parent">I am a parent</option>
<option value="I am an educator">I am an educator</option>
<option value="I am a student">I am a student</option>
<option value="I just care">I just care</option>
</select>
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;"><input type="text" name="b_3434334434_0dd34c33da" value=""></div>
<div class="clear"><input type="submit" value="MAKE A MOVEMENT" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
</form>
</div>
<!--End mc_embed_signup-->
</div>
<!-- /.formWrapper -->
<div id="response">
<? require_once('inc/store-address.php'); if($_GET['subscribe']){ echo storeAddress(); } ?>
</div>
store-address.php(通过 Mailchimp 发送详细信息并输出我的thankyou.html)
<?php
function storeAddress(){
// Validation
if(!$_GET['email']){ return '<p class="statusJoin">No email address provided</p>'; }
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
return '<p class="statusJoin">Email address is invalid</p>';
}
require_once('MCAPI.class.php');
// grab an API Key from http://admin.mailchimp.com/account/api/
$api = new MCAPI('12345fakeAPIkey-us4');
$merge_vars = Array(
'email' => $_GET['email'],
'FNAME' => $_GET['FNAME'],
'MMERGE2' => $_GET['MMERGE2'],
'MMERGE3' => $_GET['MMERGE3']
);
// grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
// Click the "settings" link for the list - the Unique Id is at the bottom of that page.
$list_id = "fakeListID12345";
if($api->listSubscribe($list_id, $_GET['email'], $merge_vars) === true) {
// It worked!
echo '<script>';
echo '$( "#formWrapper" ).hide();';
echo '$( "#response" ).hide();';
echo '$( "#response" ).show();';
echo '</script>';
readfile("../thankyou.html");
}
else {
// An error ocurred, return error message
return 'Error: ' . $api->errorMessage;
}
}
// If being called via ajax, autorun the function
if($_GET['ajax']){ echo storeAddress(); }
?>
这是 thankyou.html
输出人名
<html lang="en">
<body>
<h2 class="thankYou">Thank you, <?php echo $_POST["FNAME"]; ?></h2>
</body>
</html>`
最佳答案
要使其完全正常工作,您必须将index.html 重命名为index.php。如果它不是 PHP 文件,它就无法执行它所拥有的任何 PHP 代码,因此它永远不会包含文件 store-address.php。
在thankyou.php(重命名)中,您必须使用GET方法,因为这是您的表单使用的方法:
<h2 class="thankYou">Thank you, <?php echo $_GET["FNAME"]; ?></h2>
要获取thankyou.php的内容,您只需更改此行即可:
readfile("../thankyou.html");
至:
include 'thankyou.php';
关于javascript - 将注册表单中提交的姓名发布到感谢页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22567275/