I want to send a download link to user by mailchimp, after they filled out a email form.
The PHP Request listener is calling my_function()
, but inside this function the action is not called.
The functions and the action are working. Also after put the do_action();
inside the createDownloadButton()
it will be called. Only after write the action inside my_function()
it doesn't work?!
Inside the functions.php
:
/**
* Place a button
* @return string html-form
* usage: [download_button download_name='my_download']
*/
function createDownloadButton($atts ){
//shortcode input
$a = shortcode_atts( array(
'download_name' => ''
), $atts );
$result = '<form class="form" method="post" action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '">';
$result .= '<input hidden name="title" value="'.$a['download_name'].'" type="text" >';
$result .= '<p>';
$result .= '<input autofocus class="imput_mail" name="email" placeholder="email adress*" value="" type="email" required>';
$result .= '<input class="bt" id="btn" onClick="ga(\'send\', \'event\', \'push_button\', \'some_analytics_event\');" value="" type="submit">';
$result .= '</p>';
$result .= '</form>';
return $result;
}
add shortcode('download_button', 'createDownloadButton' );
/**
* PHP request listener
*/
if( isset($_POST['email']) && isset($_POST['title']) ){
my_function($_POST['email'],$_POST['title']);
}
/**
* Do some action here
*/
function my_function($mail, $title){
//echo works!
echo "<script>console.log( 'email: ".$mail." | download: ".$title."' );</script>";
//why the action doen't work here?
do_action('memberToMailchimpList', '<API-KEY>', $mail, '<LIST-ID>', '<INTEREST>');
}
memberToMailchimpList
?