Forum

Thread tagged as: Problem, Blog, MailChimp

On form submit, via blog post, URL format changes

Hi

I am adding a mailchimp form to my blog posts, when I click the submit button, on form submit, it changes the URL format.

URL format is: https://website.uk/blog/2016-10-16-blog-post-name/

After submit button is pressed: https://website.uk/blog/post.php?s=2016-12-09-adding-svg-icons-to-a-sprite-with-perch-cms

Any idea what I have done wrong?

Diagnostic Report

    Perch: 2.8.32, PHP: 5.5.38, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 15d5c781cfcad91193dceae1d2cdd127674ddb3e $, with PDO
    Server OS: Linux, cgi-fcgi
    Installed apps: content (2.8.32), assets (2.8.32), categories (2.8.32), perch_blog (5.0), perch_forms (1.8.3), perch_mailchimp (3.0.1)
    App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_blog', 'perch_mailchimp' );
    PERCH_LOGINPATH: /cms
    PERCH_PATH: /home/sites/juanfernandes.uk/public_html/cms
    PERCH_CORE: /home/sites/juanfernandes.uk/public_html/cms/core
    PERCH_RESFILEPATH: /home/sites/juanfernandes.uk/public_html/cms/resources
    Image manipulation: GD
    PHP limits: Max upload 64M, Max POST 64M, Memory: 128M, Total max file upload: 64M
    F1: 2edba60ed1f613d6dd804feb202456a2
    Resource folder writeable: Yes
    HTTP_HOST: juanfernandes.uk
    DOCUMENT_ROOT: /home/sites/juanfernandes.uk/public_html/
    REQUEST_URI: /cms/core/settings/diagnostics/
    SCRIPT_NAME: /cms/core/settings/diagnostics/index.php

Form

<perch:form id="subscribe" app="perch_mailchimp" double-optin="true" class="form form--subscribe">

    <perch:success>
        <p>Thank you!</p>
    </perch:success>

    <div class="content">
        <p><b>Stay up-to-date with my blog posts and receive occasional emails from me.</b></p>
        <div class="row">
            <div class="six cols">
                <perch:label for="firstname">First name</perch:label>
                <perch:input id="firstname" required="true" type="text" mailer="FNAME" />
                <perch:error type="required" for="firstname">Required</perch:error>
            </div>
            <div class="six cols">
                <perch:label for="email">Email address</perch:label>
                <perch:input id="email" required="true" type="email" mailer="email" />
                <perch:error type="required" for="email">Required</perch:error>
            </div>
            <div class="four cols">
                <button type="submit" value="Subscribe" id="btnsubmit" class="button--cta">Subscribe</button>
                <perch:input type="hidden" value="1" id="confirm" mailer="confirm_subscribe" />
                <perch:input type="hidden" id="list" value="your list ID goes here" mailer="list" />
            </div>
        </div>
        <small><em>No spam ever, unsubscribe anytime.</em></small>
    </div><!-- /.content -->

</perch:form>
Juan Fernandes

Juan Fernandes 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can set the action attribute on the form to match your URL format - that'll just get passed through.

Hi Drew

Many thanks for your reply.

I'm totally lost here. I've tried various values for action, it has stopped the URL changing, but the form is not submitting, im not seeing the success message.

Juan

Drew McLellan

Drew McLellan 2638 points
Perch Support

Make sure the value you set isn't incurring a redirect.

How do I set it so that its the current url?

Is my setup/how im using the mailchimp addon, different to how it was intended to be used?

So I have tested this with the form that you get out of the box with the addon, but tested it on a page on its own, not in a blog post - this works, so at least confirms the mail chimp integration is working.

And the URL does not change here, the form is at /signup/

<perch:form id="subscribe" app="perch_mailchimp" double-optin="true">

    <perch:success>
        <p>Thank you!</p>
    </perch:success>

    <div>
        <perch:label for="email">Email</perch:label>
        <perch:input id="email" required="true" type="email" mailer="email" />
        <perch:error type="required" for="email">Required</perch:error>
    </div>
    <div>
        <perch:label for="firstname">First name</perch:label>
        <perch:input id="firstname" required="true" type="text" mailer="FNAME" />
        <perch:error type="required" for="firstname">Required</perch:error>
    </div>
    <div>
        <perch:label for="lastname">Last name</perch:label>
        <perch:input id="lastname" required="true" type="text" mailer="LNAME" />
        <perch:error type="required" for="lastname">Required</perch:error>
    </div>
    <div>
        <perch:input type="submit" value="Submit" id="btnsubmit" />
        <perch:input type="hidden" value="1" id="confirm" mailer="confirm_subscribe" />
        <perch:input type="hidden" id="list" value="a6a8aad9ca" mailer="list" />
    </div>

</perch:form>

Drew, how do I just output the post url?

I thought this would do it: action="<perch:blog id="postSlug" /> but i still get /blog/post.php?s=2016-12-09-post-name/

Drew McLellan

Drew McLellan 2638 points
Perch Support

That depends on the context it's called in. I imagine you're not outputting anything and so Perch is taking over again.

View source and get the value of the action attribute.

If i put in <perch:blog id="postSlug" /> in action="" I get: action="/blog/post.php?s=2016-12-09-post-title" but I need it to be action="/blog/2016-12-09-post-title"

So what you say about nothing being output and perch taking over is correct. So any ideas what I am doing wrong (million $ question!)

Thanks Juan

Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you displaying the form?

I'm displaying the form after the blog post and before the comment form

(https://imgur.com/a/ZSxGk)

In post.php

      <?php perch_blog_post(perch_get('s')); ?>
      <?php perch_mailchimp_form('forms/subscribe-blog'); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Try:

<?php 
    perch_blog_post(perch_get('s'));
    PerchUtil::set_var('postURL', '/blog/'.perch_get('s'));
    perch_mailchimp_form('forms/subscribe-blog'); 
?>

and

 action="<perch:mailchimp id="postURL" />"

On the blog post, nothing is showing up after the actual post itself:

https://juanfernandes.uk/blog/2016-12-09-adding-svg-icons-to-a-sprite-with-perch-cms

So the subscribe form should be after the social share icons.

The post.php template:

<?php include('../cms/runtime.php');?>
<!doctype html>
  <?php
    perch_layout('global.header', array(
      'blog-post' => true
    ));
  ?>
  <body>
    <?php
      perch_content_custom('svgs', array(
        'page'=>'/cms/includes/svgs.php',
        'template'=>'SVG_icons.html'
      ));
    ?>

    <a class="skip" href="#content">Skip to content</a>

    <div class="page blog">
      <header class="page__header" role="banner">
        <?php perch_content('Logo'); ?>
        <?php
          perch_pages_navigation(array(
            'template' => array('item.html')
          ));
        ?>
      </header>

        <?php
          perch_blog_post(perch_get('s'));
          PerchUtil::set_var('postURL', '/blog/'.perch_get('s'));
          perch_mailchimp_form('forms/subscribe-blog');
        ?>

      <hr>

                <?php perch_blog_post_comments(perch_get('s')); ?>

                <?php perch_blog_post_comment_form(perch_get('s')); ?>
             </div><!-- /.cols .twelve -->

             <div class="sidebar meta / four cols">
               <?php perch_blog_categories(); ?>
               <?php perch_blog_tags(); ?>
               <?php perch_blog_date_archive_years(); ?>
             </div><!-- /.sidebar.four.cols -->
            </div><!-- /.row -->
           </div><!-- /.content -->
          </div><!-- /.container -->
      </main>
     <?php perch_content('Footer'); ?>
    </div><!-- /.page -->

    <?php perch_layout('js.footer'); ?>

 </body>
</html>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Sorry, typo. PerchUtil::set_var should be PerchSystem::set_var of course.

Ah, sorry didn't notice that.

So this fixes the issue with the URL redirecting, thank you. So the issue here was that mailchimp didn't know about 'postURL' - correct?

But the when you fill in the form and submit it, the page refreshes, but nothing happens - no thank you message, and no new subscriber.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you turn on debug, what does it output after the submit?

Am I supposed to be seeing any kind of output from enabling debug on the front end? - No output is shown

Ok i figured out what I was doing wrong

I was using this:

<button type="submit" value="Subscribe" id="btnsubmit" class="button--cta">Subscribe</button>

instead of:

<perch:input type="submit" value="Submit" id="btnsubmit" />

Thank you very much for your support Drew.