Jump to content

[SOLVED] Arggghh!!!!..... where are the BR's coming from?


dmccabe

Recommended Posts

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>

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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'] ?>"/>

Link to comment
Share on other sites

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']); ?>

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.