2016-09-20 2 views
2

좋아, 그럼 내가하려는 것은 someones 전자 메일을 사용하여 Mailchimp에 양식을 제출하기 전에 해당 전자 메일을 .txt 파일에 쓰고 싶습니다. Mailchimp는 양식에 "get"을 사용하고 "action"은 양식과 동일한 페이지가 아닌 mailchimp에서 실행됩니다. 여기에 양식에 대한 나의 코드가있다.양식을 제출하기 전에 .txt 문서에 게시하는 방법

<form id="subscribe-form1" action="https://personaltrainer.us6.list-manage.com/subscribe/post-json?u=4aeb5b710adef51ab754ll02f&amp;id=76420114ff" 
 
    method="get" class="form-inline"> 
 
     <div class="input-group"> 
 
     <input type="email" class="form-control" placeholder="Email address" name="EMAIL"> 
 

 
     <div class="input-group-btn"> 
 
      <button class="btn btn-grn" type="submit button" data-toggle="modal" data-target="#myModal">Sign Up</button> 
 
     </div> 
 
     </div> 
 
     <div style="visibility:collapse;" id="subscribe-result1"> </div> 
 
     <div class="checkbox"> 
 
      <label> 
 
      <input type="checkbox" id="mce-group[6917]-6917-0" name="group[6917][1024]" value="1024" checked="checked" style=""> 
 
      I agree to recieve FREE newsletter from Personal Trainer Food </label> 
 
     </div> 
 
     
 
<?php //this only works if I change get->post and action ="" but then it does not submit to mail chimp. 
 
//Get the email from POST 
 
$email = $_REQUEST['EMAIL']; 
 
$file = fopen("document.txt","a+"); 
 
fwrite($file,$email . "\n"); 
 

 

 
//redirect 
 
?>  
 
     
 

 
    </form>

답변

2

당신은 그것을로 리디렉션 한 후, URL에 값을 수동으로 추가 시도 할 수 있습니다 :

        ▼ 
    <form id="subscribe-form1" action="" method="get" class="form-inline"> 
     <div class="input-group"> 
     <input type="email" class="form-control" placeholder="Email address" name="EMAIL"> 

     <div class="input-group-btn"> 
      <button class="btn btn-grn" type="submit button" data-toggle="modal" data-target="#myModal">Sign Up</button> 
     </div> 
     </div> 
     <div style="visibility:collapse;" id="subscribe-result1"> </div> 
     <div class="checkbox"> 
      <label> 
      <input type="checkbox" id="mce-group[6917]-6917-0" name="group[6917][1024]" value="1024" checked="checked" style=""> 
      I agree to recieve FREE newsletter from Personal Trainer Food </label> 
     </div> 

<?php //this only works if I change get->post and action ="" but then it does not submit to mail chimp. 
//Get the email from GET ◄■■■ 
$email = $_REQUEST['EMAIL']; 
$file = fopen("document.txt","a+"); 
fwrite($file,$email . "\n");           URL PARAMETERS START 
fclose($file); // ◄■■■               ▼ 
header("Location: https://personaltrainer.us6.list-manage.com/subscribe/post-json?u=4aeb5b710adef51ab754ll02f&id=76420114ff&EMAIL=$email"); // ◄■■■ 
exit; // ◄■■■ 
?>  

    </form> 

주의는 원래 "침팬지"URL은 HTML의 상징으로 앰퍼샌드 $amp;을 포함 . 우리는 그것을 제거하고 "자연"앰퍼샌드 &을 사용할 수 있다고 생각합니다. 양식에 체크 박스가 있습니다

, 우리는 그것을 역시 추가 할 수 있습니다

fclose($file); // ◄■■■ 
if (isset($_GET["group[6917][1024]"])) // IF CHECKBOX IS CHECKED... 
    $chk = "&group[6917][1024]=1024";        URL PARAMETERS START 
else $chk = "";                 ▼ 
header("Location: https://personaltrainer.us6.list-manage.com/subscribe/post-json?u=4aeb5b710adef51ab754ll02f&id=76420114ff&EMAIL=$email$chk"); // ◄■■■ 
exit; // ◄■■■ 

변수 $email$chk는 URL의 끝에 있습니다. 결과 URL의 예는 다음과 같습니다

https://personaltrainer.us6.list-manage.com/subscribe/post-json?u=4aeb5b710adef51ab754ll02f&id=76420114ff&[email protected]&group[6917][1024]=1024

편집 :

<?php 
if (isset($_GET["EMAIL"])) { 
    $email = $_REQUEST['EMAIL']; 
    if (isset($_GET["group"])) 
     $chk = "&group[6917][1024]=1024"; 
    else $chk = ""; 
    header("Location: https://personaltrainer.us6.list-manage.com/subscribe/post-json?u=4aeb5b710adef51ab754ll02f&id=76420114ff&EMAIL=$email$chk"); 
    exit; 
} 
?> 

편집 # 2 : PHP 코드에

추가 한 if :

<?php 
if (isset($_GET["EMAIL"])) { 
    $email = $_REQUEST['EMAIL']; 
    // SAVE EMAIL. 
    $file = fopen("document.txt","a"); 
    fwrite($file,$email . "\n"); 
    fclose($file); 
    if (isset($_GET["group"])) 
     $chk = "&group[6917][1024]=1024"; 
    else $chk = ""; 
    header("Location: https://personaltrainer.us6.list-manage.com/subscribe/post-json?u=4aeb5b710adef51ab754ll02f&id=76420114ff&EMAIL=$email$chk"); 
    exit; 
} 
?> 

편집 # 3

리디렉션 형태와 자바 스크립트와 함께 자동 제출 :

<?php 
if (isset($_GET["EMAIL"])) { 
    $email = $_REQUEST['EMAIL']; 
    // SAVE EMAIL. 
    $file = fopen("document.txt","a"); 
    fwrite($file,$email . "\n"); 
    fclose($file); 
    if (isset($_GET["group"])) 
     $chk = "&group[6917][1024]=1024"; 
    else $chk = ""; 
    echo "<form method='get'" . 
     "  id='frm'" . 
     "  target='_blank'" . 
     "  action='https://personaltrainer.us6.list-manage.com/subscribe/post-json?u=4aeb5b710adef51ab754ll02f&id=76420114ff&EMAIL=$email$chk'>" . 
     "</form>" . 
     "<script type='text/javascript'>" . 
     "document.getElementById('frm').submit();" . 
     "</script>"; 
    exit; 
} 
?> 

편집 # 4 :

이것은 편집 # 2 만 텍스트 파일에 URL 저장 :

이 제출하지만 정상까지 URL이 변경되지 않는 것처럼
+1

내가 ... 내가 그것을 같은 페이지에 남아 코드와 양식을 실행할 때 답 –

+0

에 교훈 문자를해서, upvoted 한이 – davidthom42

+0

그것을 ... 본다 그런 식으로 방향을 바꾸지는 않습니다. 그것은 같은 페이지에 머물러 있습니다. 그것은 단지 이메일을 제출합니다. 같은 페이지에 머무른다. 작동 여부는 중요하지 않습니다. 나는 그것이 작동 할 때마다 이메일을 받는다. 작동하지 않을 때마다 이메일을받지 못합니다. – davidthom42

관련 문제