Page 1 of 1

Help with form value not showing

Posted: Sat Feb 19, 2011 9:20 am
by Arnora
Hi all. I am still very green to all forms of web development and probably trying to bite off more than I can chew but I am determined to get this right so here goes.

I have a very simple table which, when all fields are entered correctly, will email both the user and the site owner.

Now the following (not yet completed still testing) sets the values for the first forms fields to "empty" or " ". then displays the form via the default value.

Code: Select all

<?php
	session_start();
	include("db.inc");
	$addressA="";
	$nameA="";
	$telephoneA="";
	$postcodeA="";
	$emailA="";
	$connection = mysqli_connect($hostname, $username, $password, $database)
		or die ("Could not connect to server");
	switch(@$_GET['do'])
	{
		case "house";
			$addressA="$_POST[addressA]";
			$nameA="$_POST[nameA]";
			$telephoneA="$_POST[telephoneA]";
			$postcodeA="$_POST[postcodeA]";
			$emailA="$_POST[emailA]";
			foreach($_POST as $field => $value)
			{
				if ($value == "")
					{
						unset($_GET['do']);
						$message_house = "Required information is missing.  Please try again.";
						include("quotes.inc");
						exit();
					}
			} // end foreach
			if (!ereg("^[A-Za-z' -]{1,50}$",$_POST['nameA']))
			{
				unset($_GET['do']);
				$message_house = "$_POST[nameA] is not a valid name please amend.";
				include("quotes.inc");
				exit();
			}
			
			$sql1 = "SELECT * FROM Prices
					WHERE Item='$_POST[HouseType]'";
			$result1 = mysqli_query($connection,$sql1)
					or die ("Could not execute query1");
			$row1 = mysqli_fetch_array($result1,MYSQLI_ASSOC);
			extract($row1);
			$fprice = number_format($Price,2);
			/* send email to customer */
			$emesscust = "BLAH BLAH BLAH";
			$emesscust.= "\n\n\t Full House Cleaning Quote";
			$emesscust.= "\n\n\t $Item £$fprice";
			$emesscust.= "\n\n\t For any further information please email";
			$emesscust.= "\n\t info@EMAIL HERE";
			$emesscust.= "\n\n\t No hidden charges whatsoever - The price you see is the price you pay*";
			$emesscust.= "\n\n\n\t *available at extra cost Scotchguard Carpet Protection";
			$eheadcust = "From: donotreply@EMAIL HERE";
			$subjcust  = "BLAH BLAH BLAH";
			$mailsendcust = mail($_POST['email'],$subjcust,$emesscust,$eheadcust);
		
			/* send email to office */
			$emessoff  = "A new quote has been created";
			$emessoff.= "\n\t $_POST[name]";
			$emessoff.= "\n\t $_POST[address]";
			$emessoff.= "\n\t $_POST[postcode]";
			$emessoff.= "\n\t $_POST[telephone]";
			$emessoff.= "\n\t $_POST[email]";
			$emessoff.= "\n\t $Item £$fprice";
			$eheadoff = "From: EMAIL HERE";
			$subjoff = "Quote generated by $_POST[name]";
			$office = 'NAME <EMAIL HERE>';
			$mailsendoff = mail($office,$subjoff,$emessoff,$eheadoff);
			include("success.htm");
			
		break;
			
		case "other";
		
		default:
			include("quotes.inc");
	}
?>
Now the form field values

Code: Select all

<tr>
                  <td rowspan="3"><textarea name="addressA" id="addressA" cols="45" rows="4" value"<?php print @$addressA ?>"></textarea></td>
                  <td>&nbsp;</td>
                  <td><input name="nameA" type="text" id="nameA" size="25" maxlength="50" value="<?php print @$nameA ?>"></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>Telephone</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td><input name="telephoneA" type="text" id="telephoneA" size="25" maxlength="25" value"<?php print @$telephoneA ?>"></td>
                </tr>
                <tr>
                  <td>Postcode</td>
                  <td>&nbsp;</td>
                  <td>Email</td>
                </tr>
                <tr>
                  <td><input name="postcodeA" type="text" id="postcodeA" size="13" maxlength="13" value"<?php print @$postcodeA ?>">&nbsp;<input name="test" type="button" value="Check" onclick="testPostCode();"></td>
                  <td>&nbsp;</td>
                  <td><input name="emailA" type="text" id="emailA" size="50" maxlength="67" value"<?php print @$emailA ?>"></td>
                </tr>
Now I have tested this form (lots and lots and lots of testing) I've entered my own details and such and ensured that emails are received correctly so I know this should work. Then I added the small validation sections above and thats when the errors started.

When redirected to the form after say leaving a blank field, the only displayed value is "nameA", displayed being the only visible value on screen. Although according to the "view source" option of IE all the fields have values.

[text]<tr>
<td rowspan="3"><textarea name="addressA" id="addressA" cols="45" rows="4" value"aaa"></textarea></td>
<td>&nbsp;</td>
<td><input name="nameA" type="text" id="nameA" size="25" maxlength="50" value="nnn"></td>((This is the only visible field))
</tr>
<tr>
<td>&nbsp;</td>
<td>Telephone</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="telephoneA" type="text" id="telephoneA" size="25" maxlength="25" value"ttt"></td>
</tr>
<tr>
<td>Postcode</td>
<td>&nbsp;</td>
<td>Email</td>
</tr>
<tr>
<td><input name="postcodeA" type="text" id="postcodeA" size="13" maxlength="13" value"ppp">&nbsp;<input name="test" type="button" value="Check" onclick="testPostCode();"></td>
<td>&nbsp;</td>
<td><input name="emailA" type="text" id="emailA" size="50" maxlength="67" value"eee"></td>
</tr>
[/text]

So I'm not at all sure how or why this is happening.
Please note some of the values in the email section have not been editted to their latest counterparts.

Any help would be, as always, greatly appreciated.

Arnora

Re: Help with form value not showing

Posted: Sat Feb 19, 2011 11:46 am
by McInfo
Something is missing...

Code: Select all

value"aaa"
value="nnn"

Re: Help with form value not showing

Posted: Sat Feb 19, 2011 11:54 am
by Arnora
You are great thanks.

(you have no idea how long I've been staring at this and how small I feel right now.)

Arnora

Re: Help with form value not showing

Posted: Sat Feb 19, 2011 12:34 pm
by McInfo
Some editors, like NetBeans, will identify syntax errors like that for you.