Building a Form

Adding a custom form to collect data

Adding a custom form to your site is a common customization. There are a few guidelines for when you do this:

  • Always submit your form data using POST. Never use GET for forms. (There are exceptions of course, but if you don’t already grok best practices for that, then never use GET for forms!)
  • Use zen_draw_form, not the HTML <form> tag. Note that when you use zen_draw_form, you get the securityToken with no extra work.
  • Sanitize your inputs.

A good model for all of this is the Ask a Question feature, which has been part of Zen Cart since 1.5.7. See the following files:

  • includes/modules/pages/ask_a_question/header_php.php
  • includes/templates/template_default/templates/tpl_ask_a_question_default.php

Alternative Approach - Use a Form Builder

Another option which is highly recommended for storeowners who don’t have a developer is to use a form building tool like Wufoo.

A Wufoo form can easily be embedded on a extra define page (page_2, page_3, page_4) or an existing page like Contact Us. In the case of Contact Us, you would just edit the template file (includes/templates/YOURTEMPLATE/templates/tpl_contact_us_default.php) and replace the built-in form with the script from Wufoo. Similarly, using a define page would just mean editing the template file and inserting the script below the content div.

Still have questions? Use the Search box in the upper right, or try the full list of FAQs. If you can't find it there, head over to the Zen Cart support forum and ask there in the appropriate subforum. In your post, please include your Zen Cart and PHP versions, and a link to your site.

Is there an error or omission on this page? Please post to General Questions on the support forum. Or, if you'd like to open a pull request, just review the guidelines and get started. You can even PR right here.
Last modified November 14, 2021 by Scott C Wilson (105e558).