- WordPress Challenges
- Posts
- WordPress Challenge #2: Contact Form plugin
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:
Shortcode needs to have fields: Subject (input), Email (input), Message (textarea),
Sanitize all fields before being used for sending it,
Use wp_mail to send the email
Style it and enqueue style only on pages where the shortcode is
Display errors on top of the form
Starting Tips:
Shortcode docs: https://developer.wordpress.org/plugins/shortcodes/
Check if a post has the shortcode: https://developer.wordpress.org/reference/functions/has_shortcode/
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:
Have a function that will return fields for the contact form
Render fields from the function
Add actions before and after rendering fields
Create a custom post type “Contact Entries”
Before sending entries, create a custom post type for it
Change columns of the custom post type for contact entries
Starting Tips:
Use apply_filters when returning fields from the function
When saving entries, Subject = post title, message = post content, email = custom meta
All other fields are also saved as custom meta
Creating custom post type
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:
Create a custom table with columns: subject, message, email & custom (TEXT type and saving other data as serialized JSON)
Admin page to display data from the custom table + delete button to delete the row
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:
Check how you can create custom tables
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!
Reply