The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Success message shows when form is loaded through WordPress

Highlighted
Occasional Participant

Success message shows when form is loaded through WordPress

 Everything about the form works great, adds contacts, displays an error message if needed. (i'm using a stripped down version of the simple_form.php sample file)


But i don't know why the success message is showing up when the page is loaded. Before anyone has submitted the form.


Is wordpress doing something? If i run the php file separately,  there is no issues with the success message. But when it's included in the rest of the wp templates it shows up again. Odd. Any ideas?

4 REPLIES 4
Highlighted
Employee

PHP Sample with Wordpress

Hi Alex,


I have tested our PHP sample form in my own installation of wordpress, and have not run into the issue you are describing with the success message appearing before the form on simple_form.php is actually submitted. I have however seen some issues where Wordpress will not always inturpret PHP correctly if it is inserted into a page/post using certain plugins.


I successfully tested this using Wordpress version 2.9.2 along with the plugin 'Exec-PHP' which allows me to insert PHP directly into my pages/posts using the Wordpress editor, as long as the php code is contained within <phpcode> </phpcode> brackets.


With that being said, different versions of wordpress, modifications to simple_form.php, and use of different Wordpress plugins certainly have the potential to cause unexpected results. To continue to troubleshoot this, I would need a few pieces of information from you. You can either reply directly to this post or email our webservices support team with this information.


1. What version of Wordpress are you using?


2. What Plugins are you using in Wordpress?


3. What method are you using to insert simple_form.php into your Wordpress? Are you hard coding this into a specific page, or are you inserting php code directly into your pages/posts using the Wordpress WYSIWYG editor?


4. Please also post/attach your simple_form.php page so that I can see any modifications that have been made.


You may also want to take a look at this Wordpress Plugin, which is made to integrate some Constant Contact functinality into Wordpress. Please note that this is not created or supported by Constant Contact, but it may have some of the functionality you are looking to add.


 

David J

Highlighted
Occasional Participant

Hi thanks for the

Hi thanks for the response,


here's the code i've modified. https://dl.dropbox.com/u/949061/form.txt 


The .php file is brought in via INCLUDE into the sidebar.php (in wordpress) which is then used through out the entire site.


It's the latest version of wp, 2.9.2, there are no plugins being used currently.


Everything works just great, except for the success message displaying prematurely :)

Highlighted
Employee

Wordpress Error

Hi Alex,

 


I set up my wordpress sidebar.php to include the simple_form.php that you had posted, and I was able to replicate the same error that you were recieving with the success message being displayed before the form was submitted. In addtion, when I ran simple_form.php on its own, the page worked correctly, and the error / success message was not displayed until the form was actually submitted.


 


I believe this error is being caused because $error is being set elsewhere in wordpress, therefore it is either displaying an error or a sucess message. If you change the variable used on simple_form.php from $error to something unique (ie: $cc_error), this should hide any message until the form is actually submitted.


 


I hope this information helps. Please let us know if you have any other questions. Thanks!

David J

Highlighted
Occasional Participant

Ahh perfect that fixed it,

Ahh perfect that fixed it, simple and easy. Thank you very much David. Perhaps the sample files should be updated to something less generic? 


As a note to anyone else that reads this, don't forget to update the $error in the cc_class.php file as well.

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured