WordPress Challenge #2: Contact Form plugin

Challenge yourself and build a Contact Form plugin

Welcome to the WordPress Challenge #2.

In this challenge, we will focus on developing a contact form.

As with any challenge, you’ll be expected to try and do it all on yourself, but don’t worry.

Somewhere between 2nd or 3rd week of this month, I’ll send more tips & tricks for every challenge to get you closer.

See these challenges as exercises.

Hopefully, we’ll get subscribers who’ll send back their solutions and thus, if anyone is stuck, they’ll be able to learn from the provided solutions.

If none are sent, I’ll provide my own solutions to such in the upcoming month.

You’ll get points for solutions.

To check the status of points, you can check the public leaderboard: https://www.wpchallenges.com/leaderboard/

Junior Challenge: Form as Shortcode

Points: 1

Task:

Develop a shortcode that will output a simple contact form. This contact form, when submitted, will use wp_mail to send the email.

Requirements:

  1. Shortcode needs to have fields: Subject (input), Email (input), Message (textarea),

  2. Sanitize all fields before being used for sending it,

  3. Use wp_mail to send the email

  4. Style it and enqueue style only on pages where the shortcode is

  5. Display errors on top of the form

Starting Tips:

Medior Challenge: Customizable Form & Saving entries

Points: 2

Task:

Extend the form from Task 1 to create a customizable contact form so fields can be defined through code & all entries are saved before being sent.

Requirements:

  1. Have a function that will return fields for the contact form

  2. Render fields from the function

  3. Add actions before and after rendering fields

  4. Create a custom post type “Contact Entries”

  5. Before sending entries, create a custom post type for it

  6. Change columns of the custom post type for contact entries

Starting Tips:

  1. Use apply_filters when returning fields from the function

  2. When saving entries, Subject = post title, message = post content, email = custom meta

  3. All other fields are also saved as custom meta

  4. Creating custom post type

  5. Customizing Admin Columns

Senior Challenge: Custom Table & API

Points: 3

Task:

Create a custom table for saving entries instead of CPT and a 3rd party service for sending emails.

Requirements:

  1. Create a custom table with columns: subject, message, email & custom (TEXT type and saving other data as serialized JSON)

  2. Admin page to display data from the custom table + delete button to delete the row

  3. Use SendGrid or another service of your choice to send emails (filter out wp_mail with SendGrid smtp details OR use the SendGrid API to send email directly)

Starting Tips:

  1. Check how you can create custom tables

  2. Check code from https://wordpress.org/plugins/post-smtp/ to see how wp_mail is being filtered out to send emails through different services

How to send the code?

You can create one repo for this (& all future challenges) and have each folder contain a custom plugin for each challenge. Or create separate repos for each.

You can then reply to this through email with the link to the repo (it must be public so I can view it).

Happy Coding!

Join the conversation

or to participate.