WordPress.org

Ready to get started?Download WordPress

Forums

Quick Contact Form Without a Plugin (3 posts)

  1. vinsprinter
    Member
    Posted 1 year ago #

    Hi I am very stuck at the minute. I want to add a 3 field form to a section of my index.php page. I do not want to use a plugin. Just want to set the 3 fields in a form and have them processed by php as you would with any other form.

    Problem is when I add the <form>Data Here</form> information into the div on the index.php page with the action=process.php and method=post etc.

    I also created a page in the wordpress dashboard called process and published it. Then I set the default template to the page below

    Then I create a file called process.php and I added the <?php /*Template Name: process page */ then I add the necessary php and save it to the theme folder in the same area as the index.php file.

    Now I can see the form on the page and the necessary form fields. So in normal circumstances you would fill out the fields and hit the submit button. Then the form would look for the process.php page to process the information and sent the email.

    But when I hit the submit button all I get is an Error 404 Page Not Found.

    The text fields do not even refresh. So my questions are:

    Question 1. What am I doing wrong?

    Question 2: How do I do it right?

    This form is just to collect the customers name and email address - mail it to myself using the mail($to, $subject, etc etc) so that we can contact them back and arrange a time for a consultation.

    You can view the page here http://www.kitchens4u.ie - I am frustrated at this point in time and all help would be gratefully received.

    Cheers

    vinsprinter

  2. James Laws
    The WP Ninjas
    Posted 1 year ago #

    In WordPress you would generally never reference the action as the actual .php file. If you created a page in your admin, assigned the process.php as it's page template, and then set the url of the new page as the action I think you might get better results.

  3. vinsprinter
    Member
    Posted 1 year ago #

    Hi James,

    Many thanks for that information I have tried it but I am afraid that it is still not happening. Any chance you could take a look at the code below and tell me where I am going wrong.

    home.php (html for the form, in a div called "form" - As you will see I have the shortened url. Initially I have tried it with http://www. as well.

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    <form action="kitchens4u.ie/report-page/" method="post">
    <label for name="name">Name</label>
    <input type="text" id="name" name="name" length="30" maxlength="60" />
    <label for email="email">Email</label>
    <input type="text" id="email" name="email" length="60" maxlength="60" />
    
    <label for comments="comments">Comments:</label>
    <textarea input type="text" rows"6" columns="20" valign="top"></textarea>
    <input type="submit" value="submit" />
    </form>
    
    And if you can look at this PHP code for the report.php page I would be very grateful.
    
    <?php /* Template Name: report page */ ?>
    
    <html>
    	<head>
    
    	<?php
    
    if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['comments'])); {
    
    	echo $name = $_POST['name'];
    	echo $email = $_POST['email'];
    	echo $comments = $_POST['comments'];
    
    	if (!empty($name) && !empty($email) && !empty($comments)) {
    
    		if (strlen($name)>60 || strlen($email)>60 || strlen($comments)>150) {
    
    				echo 'The Character Amount has Been Exceeded';
    
    			}
    
    			$to = 'info@kitchens4u.ie';
    			$subject = 'You Have A Customer Enquiry';
    			$body = $name . "\n" . $comments;
    			$headers = 'From: ' . $email;
    
    		if (@mail($to, $subject, $email, $comments)) {
    
    			echo 'Thanks For Contact Us! We Will Contact You Soon!';
    
    			} else {
    
    				echo 'Sorry, an error occurred. Please Tray Again Now or Later';	
    
    			}
    
    			}  else {		
    
    				echo 'All Fields Are Required.';	
    
    					}
    			}
    
    ?>
    
    </head>
    </html>

    I appreciate you taking the time and effort to answer my post initially. Thanks James.

Topic Closed

This topic has been closed to new replies.

About this Topic