dmccabe Posted June 17, 2008 Share Posted June 17, 2008 I have a form that does some error checking. The form fields are all INPUT fields like this: <input id="element_5" name="accname" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['accname'] ?>"/> For some reason when the form is loaded for the first time all the form fields have a value of: <br /> This is when it is a new browser session and no values have been posted yet. If I clear all the values and submit the form then I get my error which I am expecting and the BR's do not return. So why are they there in the first place? where are they coming from? Here is the full code if it helps (and I pray it does). <?php SESSION_START(); $_SESSION['ldapname']; /* This checks to see if the user has logged in and has a running session. If not it redirects to login.php, but sets newuser.php as the location to return to once they have logged in */ if (!isset($_SESSION['ldapname'])) { $_SESSION['location'] = "/1car1/centralreservations/forms/corpaccount.php"; header("location:/1car1/login.php"); } echo "Accname value is ".$_POST['accname']."<br />"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Corporate Account SLA</title> <link rel="stylesheet" type="text/css" href="view.css" media="all"> <script type="text/javascript" src="view.js"></script> </head> <body id="main_body" > <?php if (isset($_POST['accname'])) { $accname = $_POST['accname']; $accmgr = $_POST['accmgr']; $acctel = $_POST['acctel']; $accno = $_POST['accno']; $contname = $_POST['contname']; $accorderno = $_POST['accorderno']; $conttel = $_POST['conttel']; if (strlen($accname) < 1 || strlen($accmgr) < 1 || strlen($acctel) < 1 || strlen($accno) < 1 || strlen($contname) < 1 || strlen($accorderno) < 1 || strlen($conttel) < 1 ) { echo "<strong><font color='#FF0000'>Error:</font> You must fill out all mandatory fields marked with * <br /></strong>"; } else { $_SESSION['accname'] = $_POST['accname']; $_SESSION['accmgr'] = $_POST['accmgr']; $_SESSION['acctel'] = $_POST['acctel']; $_SESSION['accno'] = $_POST['accno']; $_SESSION['accmgr'] = $_POST['accmgr']; if (isset($_POST['accemail'])) { $_SESSION['accemail'] = $_POST['accemail']; } if (isset($_POST['email_confirm'])) { $_SESSION['email_confirm'] = $_POST['email_confirm']; } $_SESSION['contname'] = $_POST['contname']; $_SESSION['conttel'] = $_POST['conttel']; } } /* if (isset($_POST['accmgr'])) { $accmgr = $_POST['accmgr']; if (strlen($accmgr) < 1 ) { echo "<strong><font color='#FF0000'>Error:</font> You must specify the account manager's name. <br /></strong>"; } else { $_SESSION['accmgr'] = $_POST['accmgr']; } } if (isset($_POST['acctel'])) { $acctel = $_POST['acctel']; if (strlen($acctel) < 1 ) { echo "<strong><font color='#FF0000'>Error:</font> You must specify the account manager's telephone number. <br /></strong>"; } else { $_SESSION['acctel'] = $_POST['acctel']; } } if (isset($_POST['accno'])) { $accno = $_POST['accno']; if (strlen($accno) < 1 ) { echo "<strong><font color='#FF0000'>Error:</font> You must specify the account number. <br /></strong>"; } else { $_SESSION['accno'] = $_POST['accno']; } } if (isset($_POST['accorderno'])) { $accorderno = $_POST['accorderno']; if (strlen($accorderno) < 1 ) { echo "<strong><font color='#FF0000'>Error:</font> You must specify the account manager's name. <br /></strong>"; } else { $_SESSION['accmgr'] = $_POST['accmgr']; } } if (isset($_POST['accemail'])) { $_SESSION['accemail'] = $_POST['accemail']; } if (isset($_POST['email_confirm'])) { $_SESSION['email_confirm'] = $_POST['email_confirm']; } if (isset($_POST['contname'])) { $contname = $_POST['contname']; if (strlen($contname) < 1 ) { echo "<strong><font color='#FF0000'>Error:</font> You must specify the contact name for the account. <br /></strong>"; } else { $_SESSION['contname'] = $_POST['contname']; } } if (isset($_POST['conttel'])) { $conttel = $_POST['conttel']; if (strlen($conttel) < 1 ) { echo "<strong><font color='#FF0000'>Error:</font> You must specify the contact telephone number for the account. <br /></strong>"; } else { $_SESSION['conttel'] = $_POST['conttel']; } } */ ?> <img id="top" src="top.png" alt=""> <div id="form_container"> <h1><a>Corporate Account SLA</a></h1> <form id="form_61911" class="appnitro" method="post" action=""> <div class="form_description"> <h2>Corporate Account SLA</h2> <p>Customer Account Details (Step 1/4)</p> </div> <ul > <li id="li_5" > <label class="description" for="element_5">Account Name *</label> <div> <input id="element_5" name="accname" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['accname'] ?>"/> </div> <p class="guidelines" id="guide_5"><small>Enter the account name. (MANDATORY)</small> </p> </li> <li id="li_1" > <label class="description" for="element_1">Contact Name * </label> <div> <input id="element_1" name="contname" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['contname'] ?>"/> </div> <p class="guidelines" id="guide_1"><small>Account customer's contact name. (MANDATORY)</small></p> </li> <li id="li_2" > <label class="description" for="element_2">Account No * </label> <div> <input id="element_2" name="accno" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['accno']; ?>"/> </div> <p class="guidelines" id="guide_2"> <small>Customer account number. (MANDATORY) </small></p> </li> <li id="li_3" > <label class="description" for="element_3">Order No: </label> <div> <input id="element_3" name="accorderno" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['accorderno']; ?>"/> </div> <p class="guidelines" id="guide_3"><small>Customer account order number.</small></p> </li> <li id="li_4" > <label class="description" for="element_4">Contact E-mail Address </label> <div> <input id="element_4" name="accemail" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['accemail']; ?>"/> </div> <p class="guidelines" id="guide_4"><small>Enter the account customer's e-mail address.</small></p> </li> <li id="li_6" > <label class="description" for="element_6">Contact Tel No. * </label> <div> <input id="element_6" name="conttel" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['conttel']; ?>"/> </div> <p class="guidelines" id="guide_6"><small>Enter the contact telephone number for the customer. (MANDATORY)</small></p> </li> <li id="li_7" > <label class="description" for="element_7">Account Manager's Name * </label> <div> <input id="element_7" name="accmgr" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['accmgr']; ?>"/> </div> <p class="guidelines" id="guide_7"><small>Enter the name of the account manager. (MANDATORY)</small></p> </li> <li id="li_8" > <label class="description" for="element_8">Account Manager Tel. * </label> <div> <input id="element_8" name="acctel" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['acctel']; ?>"/> </div> <p class="guidelines" id="guide_8"><small>Enter the contact telephone number for the account manager. (MANDATORY)</small></p> </li> <li class="buttons"> <input type="hidden" name="form_id" value="61911" /> <input id="saveForm" class="button_text" type="submit" name="submit" value="Next" /> </li> </ul> </form> </div> <img id="bottom" src="bottom.png" alt=""> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/ Share on other sites More sharing options...
DeanWhitehouse Posted June 17, 2008 Share Posted June 17, 2008 Don't double post. Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567228 Share on other sites More sharing options...
dmccabe Posted June 17, 2008 Author Share Posted June 17, 2008 I'm not the other post was regarding error checking which is now working fine. This is a separate issue? Some help would have been better this is really bugging me Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567231 Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 I just loaded up the code and don't get any BRs. Try a Ctrl-F5 to force a full refresh. Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567232 Share on other sites More sharing options...
r-it Posted June 17, 2008 Share Posted June 17, 2008 <input id="element_5" name="accname" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['accname']; ?>"/> copy and paste that as it is Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567235 Share on other sites More sharing options...
dmccabe Posted June 17, 2008 Author Share Posted June 17, 2008 Ok so I did what you both asked, no joy! However I then thought I would check in IE (normally use Firefox) and instead of the BR I now see this in all the form fields: <br /><b>Notice</b>: Undefined index: accname in <b>C:\wamp\www\wordpress\1car1\centralreservations\forms\corpaccount.php</b> on line <b>127</b><br /> so it is because the $_POST['accname'] isnt defined, but how do I get round it? Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567243 Share on other sites More sharing options...
conker87 Posted June 17, 2008 Share Posted June 17, 2008 That's ok, that's the error checking doing it's job. You've just told php to tell you absolutely everything that's wrong or slightly annoying. Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567248 Share on other sites More sharing options...
dmccabe Posted June 17, 2008 Author Share Posted June 17, 2008 yeah I switched it on because I wasnt getting any errors at all, so how do I make it so it tells me about error's such as missing semi-colons etc, but doesnt give me this undefined index nonsense? Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567249 Share on other sites More sharing options...
xoligy Posted June 17, 2008 Share Posted June 17, 2008 im not too good with php but i noticed this error near the top: echo "Accname value is ".$_POST['accname']."<br />"; shouldn't it be: echo "Accname value is '.$_POST['accname'].'<br />"; hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567259 Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 if you set error reporting to error_reporting = E_ALL & ~E_NOTICE it will remove the notices. you can also fix the code by changing them all to: <input id="element_5" name="accname" class="element text medium" type="text" maxlength="255" value="<?php if(isset($_POST['accname'])) echo $_POST['accname'] ?>"/> Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567266 Share on other sites More sharing options...
dmccabe Posted June 17, 2008 Author Share Posted June 17, 2008 Hoorah!!! Editted my php.ini to error_reporting = E_ALL & ~E_NOTICE and all is good!!!! Xoligy > Thanks for the help - however that line was simply there as a last minute bit of error checking. Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567268 Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 on another side note, if the POST values have any chance of containing quotes or < > & etc, make sure you wrap them in htmlspecialchars(): <?php if(isset($_POST['accname'])) echo htmlspecialchars($_POST['accname']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/110569-solved-arggghh-where-are-the-brs-coming-from/#findComment-567270 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.