Pawan_Agarwal Posted April 29, 2014 Share Posted April 29, 2014 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 !! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 29, 2014 Share Posted April 29, 2014 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. Quote Link to comment Share on other sites More sharing options...
Pawan_Agarwal Posted April 30, 2014 Author Share Posted April 30, 2014 okay, I will make some modification in the code and let's see if I get any problem !! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.