Jump to content
cleanboy3000

Form submitting on staging but breaking on live. How to debug?

Recommended Posts

So I have a very simple form with just 2 fields that submits on the staging site, tested and got my clients to test and everything was fine.

Uploaded exactly the same code to the live site and it works for me but my clients just get the same empty form after submitting instead of the intended thank you message that should be showing in its place...there are no error messages and I can't seem to replicate this anywhere other than on the live site and i don't want to turn debugging mode on there.

I have also checked the host for error logs but unfortunately the host doesn't seem to have this feature.

How do I debug this or any information as to why it wouldn't be working would be super helpful.

I have gotten clients to hard refresh and clear browser cache. They have tried on multiple machines and in different places with the same result.

If you would like to take a look the staging site is here: http://ams.staging.gooi.ltd/

It's the Newsletter Sign Up button in the top left. This has been working for everyone that has tried though....like I said...only seems to not work on the live site for some people.

This is the form code: 

<?php
                            $out = "";

                            $out .= '<h2 class="text-white text-center pusher">SIGN UP FOR THE LATEST NEWS</h2>';
                            $out .= '<p class="text-white text-italics nomargin">Enter your name and email below:</p>';

                            // create a new form field (also field wrapper)
                            $sform = $modules->get("InputfieldForm");
                            $sform->action = "./?modal=newsletter-signup";
                            $sform->method = "post";
                            $sform->attr("id+name",'newsletter-signup');

                            $field = $modules->get("InputfieldText");
                            $field->skipLabel = true;
                            $field->attr('id+name','newsletter_name');
                            $field->attr('placeholder','Name');
                            $field->required = 1;
                            $sform->append($field); // append the field

                            // create email field
                            $field = $modules->get("InputfieldEmail");
                            $field->skipLabel = true;
                            $field->attr('id+name','newsletter_email');
                            $field->attr('placeholder','Email');
                            $field->required = 1;
                            $sform->append($field); // append the field

                            // oh a submit button!
                            $submit = $modules->get("InputfieldSubmit");
                            $submit->attr("value","Submit");
                            $submit->attr("class","cta blue pusher");
                            $submit->attr("id+name","newsletter_submit");
                            $sform->append($submit);

                            //$out .= $sform->render();

                            // form was submitted so we process the form
                            if($input->post->newsletter_submit) {

                                // user submitted the form, process it and check for errors
                                $sform->processInput($input->post);

                                if($sform->getErrors()) {
                                    // the form is processed and populated
                                    // but contains errors
                                    $out = $sform->render();
                                    echo $out;
                                } else {

                                    $name = $sanitizer->entities($input->post->newsletter_name);
                                    $email = $sanitizer->email($sform->get("newsletter_email")->value);

                                    $name = explode(' ', $name);
                                    $lastName = end($name);
                                    unset($name[count($name)-1]);
                                    $firstName = join(' ', $name);

                                    $mc = $modules->get("SubscribeToMailchimp");
                                    $mc->subscribe($email, ['FNAME' => $firstName, 'LNAME' => $lastName]);

                                    $out = "<p class='text-white text-center pusher'>Thank you for signing up to receive the latest news on The Advanced Materials Show.</p>";
                                    
                                    echo $out;
                                }
                            } else {
                                // render out form without processing
                                $out .= $sform->render();
                                echo $out;
                            }
                        ?>

 

Share this post


Link to post
Share on other sites
<div class="headshot center-block" style="background-image:url('<br />
<b>Notice</b>:  Trying to get property of non-object in <b>/home/drumming/ams.staging.gooi.ltd/site/assets/cache/FileCompiler/site/templates/home.php</b> on line <b>214</b><br />
');"></div>

Not the reason but something I found twice in your code and you might want to fix 😉

  • Like 1

Share this post


Link to post
Share on other sites

Did you fix it? I am getting a success message:

image.thumb.png.820a1a496a3cacfa9330a53beef68529.png

First you should install TracyDebugger. If you are logged in as a superuser, it will provide a nice debug bar, which catches and reports errors.

Secondly you can look at Setup > Logs. There you have an error and an exceptions log.

  • Like 1

Share this post


Link to post
Share on other sites
Quote

Did you fix it? 

No, it works on the staging site for everyone that has tried it but on the live site it doesnt work, this is the real issue. I gave the staging site just to show the whole thing in action but removed it from the live site because, well, its a live site. This also rules out tracydebugger unfortunately...

I have checked the logs in processwire and nothing comes up.

Share this post


Link to post
Share on other sites

why , i use tracy on all live sites

  • Like 2

Share this post


Link to post
Share on other sites

Go to /processwire/module/edit?name=TracyDebugger edit Tracy's settings:

547425266_ModuleTracyDebuggerpwtwig.test2019-09-2009-40-33.jpg.5caa0a23e8ca070fc9e67b56779d1610.jpg

Check this option

1060213737_ModuleTracyDebuggerpwtwig.test2019-09-2009-41-21.jpg.6cad6bf0cac39616359a9c01ad5135d0.jpg

That way only Superusers can see Tracy on the live site.

Hope that helps

 

  • Like 3

Share this post


Link to post
Share on other sites

Hey, thanks for this...managed to get tracy debugger installed.

The really annoying thing about this is that once I install it and activate it and try the form submission...it works. Log out and try again and it fails...super annoying.

There is an error that keeps cropping up though: 

info 2019‑09‑23 18:00:36 https://advancedmaterialsshow.com/ Warning: count(): Parameter must be an array or an object that implements Countable in /path/to/processwire/wire/core/PageArray.php:631

Not really sure if this has anything to do with it or if its anything I can do anything about as it seems to be something to do with the core?

Share this post


Link to post
Share on other sites

What version of Processwire are you using?  What version of PHP are you using?  Older versions of Processwire might not be compatible with the newer versions of PHP 7.X.

Share this post


Link to post
Share on other sites

ProcessWire 3.0.62 and its PHP 7.3

The odd thing though is that the form submission works when Tracy Debugger is active but then breaks when it is not active...which makes me think its not anything to do with PHP version.

Can we learn anything from this? 

Tracy Debugger must implement something that fixes what I am looking to fix but I have no idea what that is or how to find that out 😕

Share this post


Link to post
Share on other sites

Yes...the standard template caching that comes with processwire.

If you are looking for the form on the live site and thats why you are asking, as it is a live site I have replaced the button with a link that does work for now.

Share this post


Link to post
Share on other sites

No, I'm asking because if you are logged in and it works it might be because caching is disabled when logged in. On DEV caching is likely also disabled so that could explain why it works there. Is the not-working form somewhere online to check?

  • Like 2

Share this post


Link to post
Share on other sites

Well thats the wierd thing...it is working everywhere else it is online. (on a staging site)

That being said...caching is disabled on that staging site so ill try disable caching and test again.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...