...

View Full Version : server side validation



cdc515
10-20-2009, 10:48 PM
I was wondering if anyone could help me i am doing server side validation for my php form and whenever it checks i lose the value when it is redirected back i know for a text box you can just set the value to the php variable but how do i do it for say a select box the user has already selected to make it carry over?

i have tried this but no success


<select name="pickuphour" class="pole1" id="pickuphour">
<option value="$senderPickuphour"></option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>


this however worked for the text box's



<input name="pickupaddress" value="$senderPickupaddress" type="text" class="pole1" id="pickupaddress" />

cmancone
10-20-2009, 11:03 PM
The trick has to do with how you tell a select input what is selected. You don't set a value anywhere - you instead give the selected option the SELECTED parameter. So you would do something like this:




<?php
$selected = array( "", "", "", "" );
$selected[$senderPickuphour] = " SELECTED";
?>
<select name="pickuphour" class="pole1" id="pickuphour">
<option></option>
<option value="1"<?= $selected[1] ?>>01</option>
<option value="2"<?= $selected[2] ?>>02</option>
<option value="3"<?= $selected[3] ?>>03</option>

Make sense? It's a bit confusing because I change from php to html output. The idea is that you output <option value="..." SELECTED>label</option> for the option tag that has been selected.

cdc515
10-21-2009, 12:02 AM
im not really following where exactly do i do that after i declared the variable in the php script such as

$senderPickuphour = $_POST['pickuphour'];

my webpage im working on is at www.x.com/res_off.cfm if you want to look at the code that page calls a php script which will check the form if it is not filled the page response.php will be displayed and have the exact form displayed with a message at the top saying you must fill in the fields then when all are filled in it will send the email and goto confirmation page.
The php script which is giving me a headache haha is at www.x.com/phpscript.html

please help me out with some suggestions thanks man

I also have javascript validation in place so make sure if your trying it out to disable javascript

EDIT: Well it was working when i was testing it on http:// _off.cfm

but now its not working on the website i put it up at weird



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum