0

I am using HTML to make a form with a php processor, like so:

<?php require_once("./scripts/process.php"); ?>
<form action="" method="post">
     <input type="text" name="name" />
     <input type="submit" value="Submit" />
</form>

I have, in my PHP form, a script that echos a message that says "You didn't fill in some of the required fields. Go back and fill them in." But, when I load the page for the first time, it says "You didn't fill in some of the required fields. Go back and fill them in." How can I make it so it says this only when the form is submitted? I can't use <form action="./scripts/process.php it gives me a 500 Server Error, so I want to do it this way. Is there another PHP method to do this? If so, how? Thanks!

2

2 Answers 2

2

You can check if form have been submitted by checking $_POST value

if(!empty($_POST)) {
    // some code
}

But this can fail when there is another form on the same page. In this case, you have to do it like following

if(isset($_POST["name"])) {
    // some code
}
Sign up to request clarification or add additional context in comments.

Comments

0

just make sure only post request, require process.php

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require_once('./scripts/process.php');
}
?>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.