Click to See Complete Forum and Search --> : if(empty) statements/session variables


Jim_Madrid
02-07-2003, 08:40 AM
If anyone can help me with this I would be incredibly grateful...have spent days trying to figure this out. Here are the basics

server model: PHP (although if you know it in other server model that okay too...can translate)
database: mysql

1. I have a 2 page form. When the user fills out the info on page form he is directed to the 2nd page of the form. A session variable has been created in the 2nd form to hold all the data from the 1st page. When the 2nd page is submitted all the data (stored from page 1 and new from page 2) are sent to the database.

2. Here is the problem. On page 1, I have several form fields (like combo boxes) that need to work together. For example: I have a text field (name=phylum) in which investigators add new phylum names which are eventually sent to database field "phylum" of the same name. Next to that is a select box (name=newphylum) that has all the names that the investigors have previously entered and that are dynamically retrieved from the database field "phylum".

So when a researcher fills out page 1 of the form he/she can either add a new name or select an already existing name from the select box. But just one of these values can be sent to the database, not both.

QUESTION 1:

How can I say and where would I put something that basically says the following:

if the phylum text field is left EMPTY (i.e. they donīt add a new name) and they select instead from the select box, that it is the value from the select box and not the text box that gets sent to the database.

QUESTION 2:

How do I pass the statement from question 1 into the session variable on page 2 of my form?


Iīm at my wits end with this....Please help if you can

Thanks

Jim
Madrid, Spain

KevinMG
02-15-2003, 01:24 AM
as far as testing if it's an empty entry, try the following


if(empty($newphylum)) {
//do something with new phylum
} else {
//do something with selected phylum
}


as far as passing information between the two forms, i wouldn't personally use sessions. i'd take advantage of the $_POST (avail in PHP4.1.x or higher) variables. you can traverse all the different variables posted to your script using something like the following


while(list($key,$val) = each($array)) {
echo "$key -> $val";
}


so you could take that general idea and turn all the passed variables into hidden variables of form 2, which would all then re-post themselves to your 3rd (and final?) page....so something like this...


$hiddenList = "";
while(list($key,$val) = each($_POST)) {
$hiddenList .= "<input type=\"hidden\" name=\"$key\" value=\"$val\">";
}


do note you can run into troubles with this method when quotes are entered :(

hope that helped a bit...good luck :)

CJ@G3
03-05-2003, 11:09 AM
why not have both html and php in one file, and detect whether the form is subbmitted by something like:
if($input1)
{
#process form contents to database etc.#
}
else
{
#print html form page#
}

$input1 being an input field on the form that is mandatory.

Hope this helps a little.


CJ