Support » Fixing WordPress » How to include a form from theme directory?

  • Hey,

    I’ve built a form on my page which is made for customized ordering, and the page is called order-form. With the permalinks the url is site/order-form

    When I type <form action=”mail.php”> it tries to read the url: site/order-form/mail.php

    So I tried typing ./mail.php and ../mail.php… even /../mail.php but nothing really works for me, so how do I proceed?

    I know there’s an easy way to do this, but I’m simply not familiar enough with WP to understand how to navigate through the code 🙂

    I appreciate any help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator keesiemeijer



    Try it with get_template_directory_uri():
    or if (mail.php) is in a child theme get_stylesheet_directory_uri():

    <form action="<?php echo get_template_directory_uri().'/mail.php' ?>">

    Thank you for your help keesiemeijer but unfortunately it doesn’t solve my problem. Now it simply echoes the field values into the addres bar and breaks the form so my layout doesn’t work 🙁

    The problem is that I’ve tried all the available contact form plugins but none works, because I want the visitor to fill in measures for a certain type of product, and the best way to fill these measures up is by making 18 fields divided into 2 rows, so there’s 9 fields on each row. This isn’t possible with the plugins (the maximum i’ve reached with the plugins is 3 fields per row). So I have to do it manually by making them all <td>’s.

    PLEASE tell me if you know another solution or have an idea on how to solve this.


    Moderator keesiemeijer



    What doesn’t work with your form? Does it go to the wrong page after hitting submit?

    try it with:

    <form action="<?php echo get_template_directory_uri().'/mail.php'; ?>" method="post">

    Please provide a link to a page with the form.

    Can you paste and submit the full code of the template file with the form into a and post the link to it here? see the Forum Rules for posting code and using the pastebin.

    Thanks keesiemeijer, I really appreciate your help!

    Well I tried your line of code but it breaks my form somehow 🙁

    Here’s a link of the form (and how it should look, I changed the form action to simply: <form action=”mail.php”> because it’s the only way that doesn’t break the form):

    Here’s the code for mail.php which is under template/mail.php:

    And here’s the actual form code (it’s a little messy because the structure was difficult to get formated correctly):

    Thanks again for your help! I deeply appreciate it!

    Moderator keesiemeijer



    A longshot. After your table there is a closing </div>. Remove it

    Thanks again keesiemeijer. I removed the whole div because it’s only affecting the “input [media=all]” but the form still breaks apart when I add the line <form action="<?php echo get_template_directory_uri().'/mail.php'; ?>" method="post">

    I did though get it all working by adding this url instead wp-content/themes/colorway/mail.php . But it doesn’t seem like a smart way to solve it. Do you have any ideas?

    Moderator keesiemeijer



    but the form still breaks apart

    What do you mean by that? What part breaks, the layout?

    But it doesn’t seem like a smart way to solve it. Do you have any ideas?

    Use it, if it does what you want it to.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to include a form from theme directory?’ is closed to new replies.