Jump to content

Subscribe To Mailchimp


daniels
 Share

Recommended Posts

Hey @alexm

I just tried it myself again and it works perfeclty fine. I have tried it with one tag, or multiple. I can't find a difference in our code ?

163638152_Bildschirmfoto2022-04-01um17_12_35.thumb.png.5796c3c9b2ffa469812195cc51d96825.png

 

1374891738_Bildschirmfoto2022-04-01um17_13_56.thumb.png.330b32638d7b63f4a33520a9f1af3c99.png

I'm using the same module code as here: https://github.com/danielstieber/SubscribeToMailchimp/blob/master/SubscribeToMailchimp.module

So I'm not 100% sure how to help. Maybe @chcs can share his adapted module version with tag editing methods?

Best

Daniel

Link to comment
Share on other sites

  • 8 months later...

Thank you for creating and sharing this module with the community! I have a very elementary question. I've hit some blockage with this.

How do you validate and call the module's methods? Directly in the template? External php file?

I create a form for email subscribe.

<form method="post" action="{$config->urls->assets}inc/mailchimp.php">
  <label for="email">Email:</label>
  <input type="email" id="email" name="email" required>
  <input type="submit" value="Subscribe">
</form>

In the mailchimp.php file I am attempting to validate and call your module's methods. But seem unable to even access any .php file in the PW installation.

<?php 

//load module into template
$mc = $modules->get("SubscribeToMailchimp");

$v = new Valitron\Validator($_POST);
$v->rule('email', 'email');
if($v->validate()) {
  // The email address is valid
    $mc = $modules->get("SubscribeToMailchimp");
    $email = $input->post->email;
    $subscriber = [
      'FNAME' => $input->post->firstname,
      'LNAME' => $input->post->lastname,
    ];
    $mc->subscribe($email, $subscriber);
} else {
  // The email address is not valid, display the error messages
  $errors = $v->errors();
  print_r($errors);
}

It seems I can't call an external php file in Processwire per htaccess rules.
Any help / pointers would be very much appreciated.

Link to comment
Share on other sites

Hey, it depends on your overall website logic and what you want the user to see after the form request. I don't know the best practice and there are even some discussions right now on form submission. 

Just a few ways as an inspiration:

- Send user to same address by removing the action="" from the form or using an anchor to make sure user lands on the right position of the page. In your template of that page, check if the form is submitted. If so, handle the MC part and then show the page. On the page you can now e.g. hide the form and show a success message – or show the form with validation errors.

- Send user to a new page/template and handle the request there. Might not be just a PHP file. Make a template for it first so you can action to e.g. mywebsite.com/subscribe . Would recommend JS validation in that case, otherwise it can be annoying for the user in case of validation errors to get directed back and forth.

- Use AJAX for no page loads at all.

 Checkout out other parts of the forum or ask your question about form handling there to maybe get better answers ? 

Hope this helps, all the best for your site!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...