Jump to content

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


cleanboy3000
 Share

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;
                            }
                        ?>

 

Link to comment
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
Link to comment
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
Link to comment
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.

Link to comment
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?

Link to comment
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 ?

Link to comment
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
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...