This guide will teach you how to use the best tools to quickly create forms and embed them on your website, whether itโs a plain HTML / PHP website or a WordPress website.
Weโll begin by using some third-party companies, like Survey Monkey and Google Forms, to quickly create a form as fast as possible. We wonโt spend any time customizing colors or anything like that. This is a how to get it done QUICKLY guide. Then weโll show how to create your own form either in WordPress or in straight PHP code. The final section is about getting that form on your site.
Creating a Form in Survey Monkey
First, go to surveymonkey.com and log in to your account, or sign up for a new account. If prompted, fill out the initial questions so that you get to the first screen in their system (see figure below). You can then either choose to start from scratch, or choose a template. Choose the first template as shown in the figure, so that we can show you how to embed it on your website as quickly as possible ๐
Next, youโll be presented with a bunch of choices on how to distribute your form to the world. Letโs choose, of course, โembed on websiteโ (see figure below). Later you can try out the other distribution methods.
Next, youโll want to choose โEmbedded Surveyโ (see figure below).
Finally, youโll see the javascript code that will activate your new survey form! Click once on the block of code and its text will highlight as depicted in the figure below. When itโs highlighted, just hit Ctrl+C (or Cmd+C on Apple PCs) to copy it.
We will be pasting this code into your website in the Embedding section below, and weโll cover doing it on both a plain HTML5 website and a WordPress website!
Creating a Form in Google Forms
In order to access Google Forms, youโll first need a free Gmail account. If you donโt have a Gmail account that isโฆ unfortunate. But even if you donโt want to have a Gmail address for email purposes, you can create a free account just for the sake of logging into all of Googleโs myriad of services. This is a prerequisite for this section. Iโll assume you are able to log into Google Drive with your Google Account username, which is most likely your Gmail address.
First, go to this URL: https://drive.google.com. Once youโre logged into Google Drive, youโll see the following screen shown below. Youโll want to click on โNEW,โ then โMore,โ then โGoogle Formsโ (as depicted in red in the figure below.)
And voila! You are instantly taken to a form, ready to customize, as shown in the next figure below. No setup process. No โwizard.โ I really love this part of Google Forms. You instantly go straight to the matter at hand. And you simply click on the areas you want to edit and type right into the screen. Where it says โUntitled Form,โ just click on it and give it a name.
Next, click the โSendโ button, shown in red in the next figure. Notice also the sample names I gave to all the form sections just by clicking on them and typing.
Finally, you will reach the โSend formโ dialog box, where, as shown in the red highlights, youโll first want to click on the โ< >โ button to access the HTML embed code, then just click on the โCOPYโ button at the lower right of this dialog. This will copy the embed code to your clipboard.
Thatโs it! Youโll paste it into your website in the Embedding section below, and weโll cover doing it on both a plain HTML5 website and a WordPress website!
Creating a Form in MailChimp
First, go to MailChimp and log in, or create a free account. MailChimp is totally focused on email collection forms only. That means weโll be creating a simple form that visitors to your website use to sign up to your list, after which you can send them all weekly or monthly newsletters, updates, etc. MailChimp is one of the best, cleanest, and easiest to use email list providers out there.
Once youโve logged in, youโll want to click on โListsโ on the upper left menu (see screen below). Then click on the โCreate Listโ button to the right. Youโll be taken to a simple form you must fill out to create your mailing list. Fill this out and click โNextโ to finish this step.
Now you can see your new list on the screen. Scroll down and click on โCreate a signup formโ to proceed (see screen below).
On the next screen, youโll want to click on the โSelectโ button to the right of โEmbedded Formsโ (see screenshot below).
Finally, youโll reach the form customization screen (see below)! For the purposes of this guide, letโs just leave it as is. Scroll down and click on the code (highlighted in blue in the screenshot) and copy it to your clipboard.
Thatโs it! Youโll paste this code into your website in the Embedding section below, and weโll cover doing it on both a plain HTML5 website and a WordPress website!
Creating a Form in WordPress
Hereโs a quick tutorial on the quickest and easiest way to create a form in WordPress. This guide assumes you already have a WordPress site set up. Weโll start at the dashboard, the screen you see upon logging into your WordPress admin area. First, on the left sidebar menu, click on โpluginsโ (as highlighted in red below).
We recommend WPForms or Formidable Forms for WordPress.
On the very next screen, make sure you click the blue โAdd Newโ button (as highlighted in red below) to go to the correct plugin installation screen.
Next, type โWPFormsโ in the box highlighted below.
The first box that appears will be for โWPForms,โ one of the best WordPress form plugins available today. Click on the โInstall Nowโ button as highlighted, and it will change into a blue โActivateโ button. Click on that as well :).
Youโll immediately be taken to the WPForms intro screen, as shown below. Click the big โCreate Your First Formโ button as shown.
Next, give the form a title. I chose โSay Helloโ for mine. Then click โCreate a simple contact formโ as highlighted.
Youโll immediately be taken to a screen showing your form, including first name, last name, and email. Letโs leave everything as is for now. You can go and edit things later. For now, click on the โEmbedโ button as highlighted below, and the pop-up window displayed will appear. Iโve highlighted the embed code in blue but you donโt even have to copy this code (Youโll see why in a few more steps). Just click the โxโ to close the window, and then the big โxโ at the top right to get out of the WPForms interface and get back to the normal WordPress admin area.
Now that youโre back in normal WordPress mode, click on โPagesโ as shown below, in the left sidebar menu. This is where weโll temporarily activate the form, for now.
Next, click โAdd newโ at the top left (as shown below).
Now youโll be in the page editing screen. You probably wonโt see the big purple โDivi Editorโ buttons I have but ignore that. Youโll see the highlighted button โAdd Form.โ This button exists because you installed the WPForms plugin (WordPress plugins can add little menus and buttons all over the place, in fact.). Click on it.
Youโll see a pop-up with our โSay Helloโ form showing as the first choice in the drop-down. Just click the blue โAdd Formโ button at the lower right of this window to move on.
Now youโll see the shortcode text that you didnโt have to copy earlier automatically inserted into the editing area :). Now just click the blue โPublishโ button as highlighted below.
Once thatโs done, youโll see a box at the top of your screen that says โPage published. View pageโ. Click on that link (as shown) to view your brand new live form!
Yep, a basic form. Looks good! If you fill it out and click submit, it would be emailed to the email specified as the WordPress administratorโs email address. Letโs go back and double check that you have this the way you want it. Close out of your live form and go back to the WordPress admin area.
Again, on the left sidebar menu, click โUsersโ (as shown popped out in blue below). The first user is the admin account, and please ensure the email is correct. If not, or if youโre not the admin, you can go back to the WPForms settings screen by clicking on โWPFormsโ in the left side menu (just three above โUsersโ ;-).
Thatโs it! Be sure to fill out your live form and make sure it goes to your specified email address correctly. You can add the form to any page or blog post by clicking that โAdd Formโ button on any page or post editing screen.
Whatโs great about WPForms is that with the pro version, you can get plug-ins for MailChimp and lots of other marketing tools. I also find that its plugin interface is really sleek and nicely designed. Gravity Forms and Ninja Forms are also two other well-known, wonderful WordPress form plugins you can try out as well.
Creating a Form in PHP
This section will outline the basic steps of creating a form in straight PHP for your website. This is pure HTML and PHP code โ no WordPress, no embedding a third party form, just pure coding! This is by far the most complicated method, and the steps in this section might well generate many more questions for you than there are steps! Still, almost any good content creator, marketer, or basic website owner should have a basic familiarity with these tools and this method of editing a website.
Weโre going to start with a basic Google search for โphp contact form.โ Google automatically suggested I add โwith validationโ to my search, and as a web developer I agreed (see image below) โ validation basically means the little messages that pop-up when you leave a form field blank, for example, which says โthis field cannot be blankโ.
In the red circle shown below, Iโm showing the search result on GitHub, which is a huge community where typically great developers share their code. The top engineers in the world who earn six-figure salaries showcase their work on GitHub. Furthermore, any project on GitHub can be downloaded without any annoying email subscription pop-ups. Letโs check it out!
Once youโre on GitHub, look for the green โClone or downloadโ button on the right side of the page. Click on it to reveal a small pop-up. Click on โDownload ZIPโ (highlighted below). If youโre a seasoned developer, you might choose to clone the project into your own git repository (what GitHub is named after), but if you knew how to do that you probably wouldnโt be reading this guide ;-).
The ZIP file has downloaded into your downloads folder by now, but before we go looking for it, I must stress that you should scroll down every time youโre on GitHub and read (or at least skim) the documentation for the project! This is what those aforementioned seasoned engineers would call RTFM, which is short for โRead The …. umโฆ Fahrvergnรผgenโฆ Manualโ ๐
In the highlighted section below you see that you must edit the file called โconfig.phpโ and fill in what your from and to e-mail addresses will be so that the contact form can properly send out emails. If you just rushed straight to the ZIP file first, you would end up being lost and frustrated for hundreds of hours until you threw your computer over the cliff you happened to be sitting next to while working on this contact form.
In the next screen below, Iโm showing the ZIP file that was downloaded to my โDownloadsโ folder in OS X, which I use on my MacBook Pro. If I had a Windows machine, this could be in a different place, of course.
Notice inside the outer folder there are a bunch of files and a folder named โcontact-formโ at the top of the list. Generally, this outer listing of files are very techy developer stuff and you donโt need to worry about it. The file named โREADME.mdโ, for example, is actually the exact same information in the instructions on any Github project that I had you read in the previous step. So the basic pattern is that youโll take the project folder (in this case named โcontact-formโ) and just drag that into your FTP program to upload it to your website.
Again, this step can vary wildly between Mac, Windows, Linux, and whatever FTP client you use. Iโm using Mac OS X with the latest version of Transmit (version 5), possibly the best FTP client ever made! Iโve already set up a connection to my website in Transmitโs settings (youโll need to know how to do this with your FTP client). But once youโre in, youโll see something like the screen below, which is a listing of all my website files. Notice in the red circle below I just dragged the โcontact-formโ folder into my FTP window and itโs been uploaded to my website. (I also renamed it to โ_contact-formโ with an underscore at the beginning of the filename so that it goes first in the list alphabetically.)
Notice also that Iโm inside the โcontact-formโ folder, which contains the โconfigโ folder, and within that there is our special โconfig.phpโ file. This is the one you know you have to edit if you had read those GitHub instructions above! One really cool thing about Transmit is that I am able to configure it to open any text files I double-click on directly into my text editor, Sublime Text 3 (which is one of the best code editors on the planet)! This lets me skip the whole process of downloading the file, opening the downloaded file, and then re-uploading it after editing it. Instead, it just opens right in Sublime Text (with color-coded text to boot), and when I hit Cmd+S (to save the file), it automatically re-uploads to my website!
Below youโll see how my text editor looks. I highlighted the part we need to edit in yellow. Notice I filled in the relevant sections with my email addresses. I put my personal email address in the to section, and the from section is from a โwebformโ address which is fine; this is just a simple contact-form test. A real setup might have used โinfo@โ or โno-reply@.โ
OK! After editing that file, our contact form is finished! We can go right to the live URL: https://plu.sx/_contact-form/index.php. Notice the form looks pretty nice, and the form validation works if you try to hit send without filling everything out.
Once you fill out the form correctly, youโll get to the final screen after hitting send. The form message displays โEmail sent successfully.โ Great!
But beware!! Just because the contact form thinks the message went out to you doesnโt mean youโll get an email. Again, this step can vary wildly as there are thousands of server setups, web hosting companies, and PHP configurations that can cause any number of issues. If you actually donโt get an email, youโll have to troubleshoot your server (or call your hosting company) and ask them what went wrong. Taking a look at the โSimpleMail.class.phpโ file hiding within the โcontact-formโ folder I can see itโs using the PHP โsendmail()โ function to handle e-mail delivery. Luckily for me, this worked fine without any further headaches and the contact-form was working fine at this point.
Thatโs it! As you can see, the PHP version of this guide is very involved, wrought with potential mishaps, very hard to troubleshoot, and fraught with terror! Now you can viscerally see why companies such as MailChimp are so successful. They handle all the server setup and code on their end and just give you a simple embed code. The amount of complexity is reduced by up to 99%, and the ease-of-use increased conversely.
But if youโre set on using a PHP solution, then you should be adept at completing all these steps, and you do, in the end, have ultimate control over how to customize the form and how it works. There are virtually no limits to what you can program with HTML, PHP, and Javascript. For instance, you could make your contact form email you, save the visitorโs name to a separate database, and even connect to MailChimp or any of the other services we went over, all from one single click of the โSendโ button.
Embedding a Form Into Your Website
In this section weโll cover embedding a form on your website, both in WordPress and in straight HTML.
First, choose which embed code (that we generated in one of the sections above) youโll want to use:
Here is our MailChimp embed code
Here is our SurveyMonkey embed code
Here is our Google Forms embed code
Interestingly enough, each of these services uses a different embed approach. MailChimp just gives you a plain block of HTML. SurveyMonkey gives you a block of javascript which creates the form HTML for you. And Google forms gives you an iFrame, which is like a little window directly to their website. Each of these methods requires that you either paste the code somewhere in between the <body></body> tags on one of your web pages for a plain HTML page or in the appropriate area of WordPress if youโre using that. Letโs review each:
Embedding Your Form in a Plain HTML Website
Youโll need to have an FTP client to access the files on your website and paste the code within. What youโll end up with is a page similar to this demo page Iโve prepared on my website.
Here youโll see the contact forms we created above, and if you choose Cmd+Opt+U in Google Chrome youโll open up the โview sourceโ page which will display the HTML code for this page. If you read through this code youโll see how the various embed codes above were simply pasted below the pageโs top <body> tag. I added a small bit of CSS to center each form in a nice box and pop them out from a gray background so itโs easier for you to see them.
Embedding Your Form in WordPress
First, youโll have to be logged in to your WordPress dashboard. Again, this assumes you have WordPress set up already. So in that case, log into your WordPress admin area and weโll start by clicking the โPluginsโ menu circled in red below. Then click the โAdd Newโ button on the top left of the Plugins page shown below.
Note: Weโre going to find and install the XYZ Snippets plugin which helps preserve HTML perfectly. If you try to paste HTML or Javascript directly into a WordPress post or page without any help from a plugin like this, you may get wonky effects because WordPress likes to add a bunch of formatting stuff automatically.
Now type โinsert html snippetโ into the plugin search field and youโll see the screen below. Click โinstall nowโ (circled in red below), then immediately after click โActivate.โ
Once youโve done this, youโll have the โXYZ Snippetsโ menu in the left side-menu in WordPress. (See circled below.) Click on that to get to the plugin page, then click the blue โAdd New HTML Snippetโ button at the top of the page.
Now in this next screen below, letโs just call the snippet โGoogle Formsโ and letโs just paste the Google Forms HTML code we showed above into the form. Finally, just click โCreate.โ
Now youโll see the screen below, with the HTML snippet shortcode highlighted in blue below. You could select it here and copy it, but you wonโt have to. Letโs just move on.
Click on the โPagesโ left side menu option as shown below, then either click โAdd Newโ at the top of the screen or edit an existing page. For now, Iโll edit the โtest formโ page that we created in the section above.
Now, check for the area I circled in red below. Again, WordPress plugins can create new buttons throughout the system. Remember, when we added the WPForms plugin above, we got the new โAdd Formโ button, and now we have this new โInsert HTML snippetโ button. Youโll see the one snippet we created, โGoogle Formโ showing in the menu. Click on that and the shortcode you didnโt need to copy earlier automatically gets added to the editing window below! I decided to move the Google Form shortcode to the top of the window for this demo (above the WPForms shortcode we created earlier on). Finally, click the blue โUpdateโ button, also circled in red below.
Finally, click โView pageโ circled in red below!
This will take you to your live WordPress page with, voila! Your Google Form embedded nicely within. Hereโs the live URL: https://carlosaugusto.net/test-form.