Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP contact form returning the PHP code when I press the submit button

Tags:

html

forms

php

I created a contact form for my website. When I click the submit button, it just shows the PHP code instead of the message it is supposed to show, like the text information the user inputs into the form.

Here is the HTML code for the form:

<html>
    <link href="contact.css" rel="stylesheet" type="text/css" />
    <head>
        <title>Contact Us</title>
    </head>

    <body>
        <form action="contact.php" method="post">
            <div id="ContactForm">
                <fieldset>
                    <h4>Contact Parquest:</h4>

                    <label class="labelone" for="name">Name:</label>
                    <input name="name"/>

                    <label for="email">Email: </label>
                    <input name="email"email"/>

                    <label for="commens">Comments: </label>
                    <textarea name="commens"></textarea>
                </fieldset>
                <fieldset>
                    <input class="btn" type="submit" value="Send Email"/>
                    <input class="btn" type="reset" value="Reset Form"/>
                </fieldset>
        </form>
        </div>
</html>

I couldn't post the PHP code, because it just doesn't show when I try, so here's a screenshot:

Enter image description here

like image 317
Dennis Orlovski Avatar asked May 26 '15 05:05

Dennis Orlovski


People also ask

How do you trigger a form submit from a button?

You can tie a submit button to a form that the button doesn't live inside of. The trick is to give the form an id and then reference that id with the button's form property. With this setup, clicking the Submit button will cause the form to be submitted.

How run PHP form submit?

Use isset() method in PHP to test the form is submitted successfully or not. In the code, use isset() function to check $_POST['submit'] method.

How do you get information from a form that is submitted using the GET method?

The Correct Answer is " Request.

Does submit button enter form?

Yes, structurally the submit button needs to be inside a form element for the document to be valid X/HTML. But visually you can position the submit button anywhere you want with appropriate CSS (float, absolute/relative positioning, etc).


2 Answers

I faced the same problem and when I tried starting my own server it worked. when you are using Windows, open cmd and type in this;

php -S localhost:4040;

you will see something like this

PHP 8.1.1 Development Server (http://localhost:4040) started

meaning you have started your own server, then you can copy the link found in the parenthesis

so you copy say this "http://localhost:4040" and paste it in your browser then you can now direct it to your html document like this

http://localhost:4040/Desktop/Projects/index.html

now your form should work well with your php script when you submit

like image 107
Anamboi John Avatar answered Sep 17 '22 18:09

Anamboi John


There is no problem to your code.. The problem is on your environment.. I guess you are not running the html file through a server..

If the url on your browser looks like these:

file:///c:/path/to/your/file/page.html

then you are doing it wrong.. in order to run .php scripts, you need a web server like apache or nginx... the url of should be like these

http://localhost/path/to/file/page.html

then the php file should run as expected..

php files are interpreted scripting language and thus it needs an interpreter in the server in order to run.. if it is just browsed in the browser without a server, it will just output the code inside..

like image 42
catzilla Avatar answered Sep 18 '22 18:09

catzilla