FUNKAM35 Posted July 31, 2015 Share Posted July 31, 2015 <form name=\"form1\" ACTION=\"$_SERVER[REQUEST_URI]\" METHOD=\"POST\">Your First Name<br><input name=\"first\" value = \"$first\" type=\"text\" id=\"first\" size=\"25\"><br><br>Last Name<br><input name=\"last\" value = \"$last\" type=\"text\" id=\"last\" size=\"25\"><br><br>Email<br><input name=\"email\" value = \"$email\" type=\"text\" id=\"email\" size=\"25\"><br><br>Telephone Number<br><input name=\"phone\" value = \"$phone\" type=\"text\" id=\"phone\" size=\"25\"><br><br><label for=\"comments\">Comments</label><textarea name=\"comments\" cols=\"18\" rows=\"4\" class=\"txt\" id=\"comments\"></textarea><div style=\"visibility:hidden\"><input name=\"email2\" type=\"text\" size=\"45\" id=\"email2\" > </div><input type=\"submit\" name=\"Submit\" value=\"Submit\" class=\"tpc4\"></form>\n"; Hi I am getting the error message Notice: Undefined Index on the following form before submission I would like to fix this rather than suppress errors Any help would be much appreciated Quote Link to comment Share on other sites More sharing options...
FUNKAM35 Posted July 31, 2015 Author Share Posted July 31, 2015 $first1 = $_POST['first1']; $last1 = $_POST['last1']; $email1 = $_POST['email1']; $register = $_POST['register']; ok I think the error is on some different lines as posted here how can I fix this please thanks Quote Link to comment Share on other sites More sharing options...
requinix Posted July 31, 2015 Share Posted July 31, 2015 Make your code check that the form was submitted before it tries to get values from the form. One way would be to look for the submit button in $_POST as that indicates the user clicked it and thus submitted the form. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted July 31, 2015 Share Posted July 31, 2015 @FUNKAM35 - Does your page have multiple forms? If not, your $_POST variable should be "first" and not "first1"...unless there is more to your form that's not being shown. To avoid errors being shown before a form is submitted, you could check if the form was submitted before using $_POST. However, you would still need to set variables like $first so that errors don't come up while the form is being displayed. Here's a quick example: <?php //IF FORM WAS SUBMITTED if($_SERVER['REQUEST_METHOD'] == 'POST') { $first = $_POST['first']; //get the rest of the form information //ELSE...INITIALIZE FIELDS } else { $first = ''; //initialize other variables... } //dispaly form... ?> 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.