Support » Fixing WordPress » How to use forms in WordPress

  • I want to add a page to my WordPress site that contains a form. On displaying the page, the form needs to be populated from a new table that I will add to the MySQL database. The user can then change the data on the form, and click a Submit button. I then need another WordPress page to process the values returned from the form, insert them in the database, and send the user a confirmatory e-mail message.

    What’s the easiest way of doing this?

    My questions are:
    1. Can I just include the PHP to generate the form and populate it from the database in my WordPress page, maybe using the Exec-PHP plugin?
    2. What do I put in the Action attribute of the form element? Do I just put the permalink to the form processing page in here?
    3. In my form processing page, how do I access the returned values from the form? Can I just access $_POST[] like I would in PHP?
    4. Can I send e-mail from my form processing page? What’s the best way of doing this?

    Thanks – Rowan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Rowan

    I’d suggest you create a custom page template for the forms page and add your PHP code into the template page. You can bypass the page content altogether if its not needed. Then you can treat it like a regular PHP file yet WP will display it as part of your site.

    Start by pasting the code from page.php into a new template file (page_form.php ?? ).
    Add this code at the top of the new file.

    Template Name: MyForm

    Then go into the WP editor for that page, and set the Template pulldown to MyForm. That tells WP to use your custom template when displaying the contents of that page.

    See for more details.

    Rowan, the answer to all you questions is yes. But I wanted to post something that I found a bit odd. If I use a form field with the name of name the form will not post to my form action, but instead it posts to the default search page.

    This will post to the search page:

    <form action="myself.php">
        <input type="text" name="name" />

    This will post to myself.php:

    <form action="myself.php">
        <input type="text" name="title" />
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to use forms in WordPress’ is closed to new replies.