Page 1 of 1

Form problems with input select

Posted: Tue Sep 09, 2003 8:51 am
by Chaal
Hi there,

I am writing a basic form and am not 100% sure if I am doing thing correctly for drop down lists:

I have this element:

Code: Select all

<tr valign="top" align="left">
<th width="30%"><label for="fhealth">Is your health good?</label></th>
<td>
<select name="select" size="1" name="fhealth" id="fhealth" class="text" tabindex="16">
<option value="Please Select">Please Select
<option value="fhealth">Yes
<option value="fhealth">No
</select><br />
</td>
</tr>
and am using this code in the top of the page for it:

Code: Select all

$msg .= "In Good Health:\t$fhealth\n";
But when I submit the selected value is not coming though to the email. The field is just blank.

I know I am probably missing something obvious but I can't see it. I have been at the P.C. too long :)

I 'm off to Tescos for a break.

Thanks
Karl

Posted: Tue Sep 09, 2003 9:01 am
by JayBird
Could you show us the code for the entire page.

First thing i saw from your snippet is the select code should possible like this

Code: Select all

<select size="1" name="fhealth" id="fhealth" class="text" tabindex="16"> 
<option value="Please Select">Please Select</option>
<option value="Yes">Yes</option>
<option value="No">No</option
</select>

Posted: Tue Sep 09, 2003 9:20 am
by twigletmac

Posted: Tue Sep 09, 2003 10:50 am
by Chaal
Hi there,

Yep that fixed it. I told you I was too long at the co,puter :wink:

When you have long forms what is the best way to do error checking and validation?

Thanks

Posted: Tue Sep 09, 2003 10:56 am
by JAM
Depends on what you are searching for. You can (for example) use a loop, that goes through all values in the $_POST and check if any is empty, if so return to original page with err-msg.

But its all up to you. (The list of various ideas of this topic is to long to list without more information).

Posted: Tue Sep 09, 2003 12:47 pm
by Chaal
Hi gents,

I am getting there :)

I now get this error

Code: Select all

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/elyitrec/public_html/apply/allinone.php on line 42
The code in question is this:

Code: Select all

<td><input type="text" size="30" name="fpossort" id="fpossort" tabindex="1" value="<? echo $_GET&#1111;'title'] ?>" class="text" /></td>
this code is used with the following:

Code: Select all

<?
$form_block = "
What does this mean?

Thanks so much

Posted: Tue Sep 09, 2003 1:44 pm
by JAM
Chaal wrote:Hi gents,
twigletmac... ----^ ;)

You are missing the ; in the php-tag...

Code: Select all

<td><input type="text" size="30" name="fpossort" id="fpossort" tabindex="1" value="<? echo $_GET['title']; ?>" class="text" /></td>

Posted: Tue Sep 09, 2003 2:54 pm
by Chaal
Hi there,

That didn't work, Thanks anyway:

Here is my complete PHP code:

Code: Select all

<?
$form_block = "
<form method="post" action="$php_self">
<table cellspacing="0">
<tr valign="top" align="left">
<th width="30%"><label for="fpossort">Position Sought:</label></th>
<td><input type="text" size="30" name="fpossort" id="fpossort" tabindex="1" value="<? echo $_GET&#1111;'title'] ?>" class="text" /></td> 
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fref">ERS Reference:</label></th>
<td><input type="text" size="30" name="fref" id="fref" tabindex="2"\ value="<? echo $_GET&#1111;'ref'] ?>" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fname">Your Full Name:</label></th>
<td><input type="text" size="30" name="fname" id="fname" tabindex="3" value="" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="faddress1">Address1:</label></th>
<td><input type="text" size="30" name="faddress1" id="faddress1" tabindex="4" value="" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="faddress2">Address2:</label></th>
<td><input type="text" size="30" name="faddress2" id="faddress2" tabindex="5" value="" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fcity">City:</label></th>
<td><input type="text" size="30" name="fcity" id="fcity" tabindex="6" value="" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fpostcode">Postcode:</label></th>
<td><input type="text" size="30" name="fpostcode" id="fpostcode" tabindex="7" value="" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fhometel">Home Telephone:</label></th>
<td><input type="text" size="30" name="fhometel" id="fhometel" tabindex="8" value="" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fmobile">Mobile:</label></th>
<td><input type="text" size="30" name="fmobile" id="fmobile" tabindex="9" value="" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fmail">Email:</label></th>
<td><input type="text" size="30" name="fmail" id="fmail" tabindex="10" value="" class="text" /><br />
</td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fdob">Date Of Birth:</label></th>
<td><input type="text" size="30" name="fdob" id="fdob" tabindex="11" value="" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fage">Age:</label></th>
<td><input type="text" size="30" name="fage" id="fage" tabindex="12" value="" class="text" /></td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fnationality">Nationality:</label></th>
<td><input type="text" size="30" name="fnationality" id="fnationality" tabindex="13" value="" class="text" /><br />
</td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fminsal">Minimum Salary Sought:</label></th>
<td><input type="text" size="30" name="fminsal" id="fminsal" tabindex="14" value="" class="text" /><br />
</td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fchildren">Children:</label></th>
<td>
<select name="select" size="1" name="fchildren" id="fchildren" class="text" tabindex="15">
<option value="Please Select">Please Select
<option value="Yes">Yes
<option value="No">No
</select><br />
</td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fhealth">Is your health good?</label></th>
<td>
<select name="select"\ size="1" name="fhealth" id="fhealth" class="text" tabindex="16">
<option value="Please Select">Please Select
<option value="Yes">Yes
<option value="No">No
</select><br />
</td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fsmoke">Are you a smoker?</label></th>
<td>
<select name="select" size="1" name="fsmoke" id="fsmoke" class="text" tabindex="17">
<option value="Please Select">Please Select
<option value="Yes">Yes
<option value="No">No
</select><br />
</td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fcar">Do you have use of a car?</label></th>
<td>
<select name="select" size="1" name="fcar" id="fcar" class="text" tabindex="18">
<option value="Please Select">Please Select
<option value="Yes">Yes
<option value="No">No
</select><br />
</td>
</tr>
<tr valign="top" align="left">
<th width="30%"><label for="fnotice">Notice Needed:</label></th>
<td>
<select name="select" size="1" name="fnotice" id="fnotice" class="text" tabindex="19">
<option value="Please Select">Please Select
<option value="1 week">1 week
<option value="2 weeks">2 weeks
<option value="3 weeks">3 weeks
<option value="4 weeks">4 weeks
<option value="5 weeks">5 weeks
</select><br />
</td>
</tr>
<tr valign="top" align="left" class="w100">
<th width="30%"><label for="fmsg">Additional Information:</label></th>
<td><textarea rows="10" cols="30" name="fmsg" id="fmsg" tabindex="20"></textarea></td>
</tr>
<tr valign="top" align="left">
<th width="30%">&nbsp;</th>
<input type="hidden" name="op" value="ds">
<td><input type="submit" value="&nbsp; send &nbsp;" tabindex="21" class="button" /></td>
</tr>
</table>  
</form>
";
if ($op == "ds") &#123;
 //they need to see the form
 echo "$form_block";
 	
if ($fpossort == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fref == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fname == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($faddress1 == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fcity == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fpostcode == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fhometel == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fmail == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fdob == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($age == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fnationality == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fminsal == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fchildren == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fhealth == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fsmoke == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fcar == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($fnotice == "") &#123;
		$name_err = "<font color=red>Please enter your name!</font><br>";
		$send = "no";
	&#125; 
	
if ($send != "no") &#123;
	// it's O.K. to send!
	
$to = "karl@elywebsolutions.com";
$subject = "Online Application";
$mailheaders = "From: My Web Site <> \n";
$mailheaders .= "Reply-To: $fmail\n\n";
	
$msg = "Email sent from Ely IT Recruitment\n";
$msg .= "Position Sought:\t$fpossort\n";
$msg .= "ERS Reference:\t$fref\n";
$msg .= "Senders Name:\t$fname\n";
$msg .= "Address 1:\t$faddress1\n";
$msg .= "Address 2:\t$faddress2\n";
$msg .= "City:\t$fcity\n";
$msg .= "Postcode:\t$fpostcode\n";
$msg .= "Home Telephone:\t$fhometel\n";
$msg .= "Mobile Phone:\t$fmobile\n";
$msg .= "Email Address:\t$fmail\n";
$msg .= "Date Of Birth:\t$fdob\n";
$msg .= "Age:\t$fage\n";
$msg .= "Nationality:\t$fnationality\n";
$msg .= "Minimum Salary Sought:\t$fminsal\n";
$msg .= "Children:\t$fchildren\n";
$msg .= "In Good Health:\t$fhealth\n";
$msg .= "Are You A Smoker:\t$fsmoke\n";
$msg .= "Do You Have Use Of A Car:\t$fcar\n";
$msg .= "Notice Needed:\t$fnotice\n";
$msg .= "Additional Information:\t$fmsg\n";
	
mail ($to, $subject, $msg, $mailheaders);

    echo "<h2>Thank You - Your Message Has Been Sent</h2>";
    echo "<em>&nbsp;</em>";
    echo "<p>We will be in toouch We will be in toouch We will be in toouch We will be in toouch We will be in toouch</p>";
&#125; else if ($send == "no") &#123;
	echo "$fref_err";
	echo "$fname_err";
	echo "$faddress1_err";
	echo "$fcity_err";
	echo "$fpostcode_err";
	echo "$fhometel_err";
	echo "$fmail_err";
	echo "$fdob_err";
	echo "$fage_err";
	echo "$fnationality_err";
	echo "$fminsal_err";
	echo "$fchildren_err";
	echo "$fhealth_err";
	echo "$fsmoke_err";
	echo "$fcar_err";
	echo "$fnotice_err";
	echo "$form_block";
&#125; 
	
&#125;
?>

Posted: Tue Sep 09, 2003 3:30 pm
by pootergeist
$form_block = "a string <?php echo $variable; ?> more string";

is not the right way of concatenating variables in strings

either

$form_block = "a string $variable more string";
or
$form_block = 'a string' .$variable. ' more string';

Posted: Tue Sep 09, 2003 3:58 pm
by Chaal
Hi there,

I am being a real no-brainer tonight :(

So is this correct:

Code: Select all

<td><input type="text" size="30" name="fpossort" id="fpossort" tabindex="1" value="$_GET&#1111;'title']" class="text" /></td>

Posted: Tue Sep 09, 2003 4:26 pm
by Bennettman
Plus, you're missing escape slashes before the variable insert in the ERS Reference.

Posted: Wed Sep 10, 2003 3:59 am
by twigletmac
You cannot do:

Code: Select all

$str = "blah $_GET['title'] blah";
it needs to be either

Code: Select all

$str = "blah $_GET[title] blah";
or

Code: Select all

$str = "blah {$_GET['title']} blah";
however, for large blocks of HTML like you have, I would recommend heredoc syntax, it'll save on a lot double quote escaping plus it will retain your formatting.
http://www.php.net/manual/en/language.t ... ax.heredoc

Code: Select all

$form_block =<<<END
<form method="post" action="{$_SERVER['PHP_SELF']}">
<table cellspacing="0">
<tr valign="top" align="left">
<th width="30%"><label for="fpossort">Position Sought:</label></th>
<td><input type="text" size="30" name="fpossort" id="fpossort" tabindex="1" value="{$_GET['title']}" class="text" /></td>
</tr>
etc...
END;
Mac