[英]Post the name submitted in a sign up form to thank you page
我正在嘗試以Mailchimp形式張貼用戶輸入的用於注冊的名稱(名稱值為FNAME
),以顯示在我的自定義感謝頁面中(例如“ Thank you NAME HERE
,”)。 除了看到要使用*|FNAME|*
以外,我還沒有看到如何用Mailchimp的文檔進行此操作,這對我要嘗試的操作不起作用,並且意識到最好只是通過<?php echo $_POST["FNAME"]; ?>
我已經在我的thankyou.html
中包含了<?php echo $_POST["FNAME"]; ?>
,它與表單的位置( 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';
您的表單方法是GET
但是您嘗試顯示POST
變量...使用
<h2 class="thankYou">Thank you, <?php echo $_GET["FNAME"]; ?></h2>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.