0

I am new to WP and back-end in general. I want to make a site with multiple forms and I am curios how and where do I handle them ?

One of those forms is a form inside footer in which the user is supposed to input its email address in order to subscribe to a newsletter.

The footer is added via custom html and the form inside it looks like this:

        <form action="" method="post">
          <input
            type="email"
            name=""
            id=""
            placeholder="Enter your e-mail address"
          />
          <button type="submit">Sign Up</button>
        </form>

I've linked the WP site to a database and, as such, I would like to store the inputted emails into a table. How can I do that ? I am not proficient in PHP, but I don't think it's that hard to search up how to handle email forms.

The problem is that I have no idea where to write the code. I am used to creating ExpressJS handlers, but with WP I have no idea what to do.

Also, do form plugins handle the back-end as well ? Or are they only front-end elements ? And if they also handle the back-end, what plugin would you recommend for a multi-form that takes into account every choice of the user and then redirects him to the proper page/product ?

Thank you.

6
  • Can you point me to some docs or an article, guide, tutorial ? Because I have no idea how to implement what you've just said.
    – Jorje12
    Nov 27, 2020 at 15:39
  • @ChrisNorman That's not much to go on. Can you please think of something more ?
    – Jorje12
    Nov 27, 2020 at 15:49
  • Do I put the code in the custom html ?
    – Jorje12
    Nov 27, 2020 at 15:50
  • I modified my comments into an answer for you. Nov 27, 2020 at 15:58
  • How do I add then to my website ? Do I remove it from the Custom HTML and put it only in the code you've provided ? And if I remove it from the Custom HTML won't that mess up the whole design ?
    – Jorje12
    Nov 27, 2020 at 15:58

1 Answer 1

0

Forms can handle both the front end and back end. If you don't code the forms correctly, there can be some huge security issues that will arise. With what you are talking about, you will have to use a WordPress hook something like this:

function your_function() { //your form here } add_action( 'wp_footer', 'your_function' );

This will put your form in the footer on the page. You will want to put your code in a custom plugin - so that the user can add it to his/her site.

In order to do this, here are some references to point you in the right direction.

https://developer.wordpress.org/reference/hooks/wp_footer https://developer.wordpress.org/plugins/intro https://www.sitepoint.com/build-your-own-wordpress-contact-form-plugin-in-5-minutes/

The tutorial from sitepoint should get you started. The tutorial goes through some plugin building and creating a form. After you have that - just implement the code

function your_function() { //your form here } add_action( 'wp_footer', 'your_function' );

Code reference: developer.wordpress.org/reference/hooks/wp_footer

Now regarding your other question about database tables - that a whole other beast. Here is the documentation for that: https://codex.wordpress.org/Creating_Tables_with_Plugins

Depending on your level of coding experience - you may want to just find an over-the-counter plugin to handle this. There is a reason WPforms and ContactForms7 are widely used - it takes a lot of work to create a plugin that will handle forms well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.