Mailchimp embedded form validation

So I’ve successfully implemented a sign-up form for my list.

One problem I’m still having is with fields validation… whenever I leave an empty field, I get redirected to the MailChimp site - which I want to prevent and do all validation directly on my site.

Is there a way to test, where things go wrong with the php files ?
I’ve got php console chrome extension, but it doesn’t do anything.

Here are all my files.
http://progressive-overload.com/js.js

Subscribe.php

<?php
$api_key = "";
$list_id = "";
require('Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['email']) ) );
if ( ! empty( $subscriber['leid'] ) ) {
   echo "success";
}
else
{
    echo "fail";
}
?>

Mailchimp.php (11.6 KB)

1 Like

Add something like this at the top of subscribe.php

if (empty($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
    echo "fail";
    return;
}

thanks.
What was it supposed to do ? As I didn’t see any change.
Here’s the console output…

Ok, for anyone potentially interested in achieving this result, here’s a solution I’ve found.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.