0

I have made a form with the php code right under the html form code in the same file. In the php code section, the page will echo "please fill in all the fields" if the user does not fill in and submit all the important field data. Whats bugging me is that the "please fill in all the fields" message displays BEFORE the user even clicks the submit button. I don't want anything to echo out until after the submit button is clicked, thanks.

thanks in advance.

1
  • It would help if you posted your code. Commented Apr 19, 2011 at 6:13

1 Answer 1

4

You could try this

if(isset($_POST['submit'])){
    echo "please fill in all the fields";
}

Where "submit" is the value of your submit button. And maybe add something like && $_POST['important_field'] == ""

You really should have posted some actual code by the way. That would make it a bit easier. Nevertheless I think you can fix it with this.

Sign up to request clarification or add additional context in comments.

6 Comments

It would be wiser to check if submit is set, otherwise an error will be shown.
That is not true. IF it doesn't exist it 'returns' null.
Actually it will trigger a Notice. Lot of people just turn them off and don't care about them (laziness?). Using isset() would earn my upvote, since we are trying to promote best practices here.
@Nanne, a notice will be triggered if a key does not exist in array. From the manual: Attempting to access an array key which has not been defined is the same as accessing any other undefined variable: an E_NOTICE-level error message will be issued, and the result will be NULL..
I consider a notice and an error different things, but you are right about it generating a notice. I'll add it.
|

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.