tutorial08.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. Tutorial Part 8: Forms & Contact Pages
  2. ======================================
  3. Now we need a way for our customers to contact us. We could just make a simple
  4. web page with our address, phone number, and email, but we want to make some forms
  5. that specify what our customers are looking for. Good thing there is a special page type
  6. just for forms!
  7. Adding a Form page to your site
  8. -------------------------------
  9. Let's work on the "Contact Us" form we made in part 2 of the tutorial. Using the side menu select **Pages > Home > Contact Us** Click the pencil or click the title and then edit.
  10. This will take you to the editing screen.
  11. .. figure:: images/tut08/contact_us_start.jpeg
  12. :alt: The editing screen for a form.
  13. The editing screen for a form.
  14. Creating the Form page
  15. ----------------------
  16. Our contact form is going to be utilitarian, however you can add a hero unit or other content blocks in the body section. Our body section will remain blank.
  17. Click add form fields. You will be presented with this block:
  18. .. figure:: images/tut08/form_fields.jpeg
  19. :alt: adding a form field
  20. Adding a form field
  21. * **Label** is the title or name of the form.
  22. * **Help Text** is a prompt or helper text that goes directly beneath the input
  23. * **Required** is a checkbox to decide if the user has to put in a value. HTML validation will not allow a user to submit a form that doesn't have all the required form fields filled out.
  24. * **Field Type** has all the options for different types of inputs. (For this demo we will be using different types of text inputs). To learn more, read :ref:`form-fields`
  25. * **Choices** are for the values that checkbox, radio, or dropdown inputs use.
  26. * **Default value** is a value that will be inside the input.
  27. For the "Contact Us" form we want a First Name, Last Name, Email, Phone, and Message field. Notice that we changed **Field type** to match the type of input.
  28. By selecting the correct field type, the input will have better validation. For instance, the field type "email" will require the input data matches an email format before
  29. it allows the user to submit. Field type "number" will only allow numbers and some symbols like the dash "-" and ".". This is ideal phone numbers or prices.
  30. Field type "Multi-line text" is great for messages as it gives more space on the page automatically. Here's our editor and the form after we add these fields **Save draft** and **Preview**.
  31. .. figure:: images/tut08/form_fields_editor.jpeg
  32. :alt: form field editor with our inputs
  33. The form field editor with our inputs.
  34. .. figure:: images/tut08/contact_us_form_preview.jpeg
  35. :alt: Contact us form
  36. Our Contact us form.
  37. Cool, so now let's look at the rest of the settings on the from editing page. Scroll down to the Form Settings section directly below what we just worked on.
  38. * **Thank you page:** you can select a Thank You page (if you've made one). Here is what you get by default if you don't link a page:
  39. .. figure:: images/tut08/thank_you_default.jpeg
  40. :alt: thank you default
  41. thank you default
  42. * **Button text** is what the form's submit button says. It has a default value of "Submit"
  43. * **Button style** is the how the button looks. Check out `bootstrap buttons <https://getbootstrap.com/docs/5.2/components/buttons/>`_
  44. * **Button size** changes the size of the button.
  45. * **Button CSS Class** A custom CSS style applied to the button.
  46. * **Form CSS Class** A custom CSS class applied to <form> element.
  47. * **Form CSS Class** A custom ID class applied to <form> element.
  48. For CRX-Pharma, let's change the button size to large and leave the rest of the settings as they are. Next let's look at Form Submissions:
  49. * **Save form submissions** Submissions are saved to database and can be exported at any time.
  50. * **Email form submissions to:** Use this to email form submissions to an email address(es). Separate multiple email addresses by a comma.
  51. * **Reply-to-address** To reply to the submitter, specify the email field here. For example, if a form field above is labeled "Your Email", enter: {{ your_email }}
  52. * **Subject** is to give the email a subject.
  53. For CRX-Pharma, We will leave the email part blank but keep **Save form submissions** selected.
  54. Setting up Confirmation Emails
  55. ------------------------------
  56. There is also a section to setup confirmation emails. Confirmation Emails uses Django template language and HTML for best results. To learn more, read :ref:`confirmation-emails`.
  57. .. note::
  58. By default when running locally, confirmation emails are not sent, but are
  59. instead printed to the command line.