Jump to content

form submit and error message


Pawan_Agarwal

Recommended Posts

I am making a form like this

 

<form method="post">

<input type="text" name="n1"> <br>

<input type="text" name="n2"> <br>

<input type="text" name="n3"> <br>

<input type="text" name="n4"> <br>

<input type="Submit">

</form>

 

I am having some problem in managing the input from all text box, when

 

1] I enter http://127.0.0.1/test/index.php, it must work okay, it should not display any message 

 

2] if I press submit without entering values in all text boxes, it must display a message to enter in all boxes,

 

3]if I enter  all information in all boxes, it must say that you have completed the form 

 

I have tried my possible codes but I am able to do so !! Can you tell me where I am lacking !@!

 

I have tried $_REQUEST["n1"] and isset($_REQUEST["n1"]), any suggestions !!

Link to comment
Share on other sites

Do not use $_REQUEST. This mixes all URL parameters, request body parameters and cookies into one big array, which can easily lead to collisions and a lot of confusion. Explicitly fetch the values from the right source. In your case, you want $_POST.

 

Using isset() makes no sense, because even if the user leaves the fields empty, the parameters are still set. What you want is empty(). This checks if the parameter is not set or has a falsy value.

 

In addition to that, use the required attribute on the fields so that the user doesn't have to wait for your response to see that the input is wrong.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.