PDA

View Full Version : form help please



LJackson
Sep 16th, 2009, 04:33 PM
Hi All,

i require some help with a 'complex' form (complex to me that is)

i have a form with a listbox which holds several values, i am trying to get the current value when submitted to stick so when the page reloads the new value is automatically selected, also is it possible to set the value of a varible to the current listbox value? i want to use the current value in my url.

here is my code

<form id="filter" action="price_results.php?title=<?php echo urlencode($title)?>&amp;category=<?php echo $category?>&amp;platform=<?php echo $platform?>" method="POST">

<div>
<label for="cat_select"><strong>Platform: </strong></label>
<select id="cat_select" name="platform">
<?php

//fill the list box with platform array
foreach($array2 as $plat)
{
if($platform==$plat)
{
echo "<option value=\"{$plat}\" selected=\"selected\">{$plat}</option>";
print $platform;
}
else
{
echo "<option value=\"{$plat}\">{$plat}</option>";
}
}
?>
</select>

<input type="submit" name="submit" id="submit" value="Filter" /></div>
</form>

any ideas please
Thanks

LJackson
Sep 16th, 2009, 05:15 PM
ok i have managed to retain the listbox value on page reload :)


<form id="filter" action="price_results.php?title=<?php echo urlencode($title)?>&amp;category=<?php echo $category?>&amp;info=<?php echo $platform?>" method="POST">

<div>
<label for="cat_select"><strong>Platform: </strong></label>
<select id="cat_select" name="platform">
<?php
//fill the list box with platform array
foreach($array2 as $value)
{
$plat = (isset($_POST['platform']) && $_POST['platform'] == $value) ? ' selected' : '';
echo '<option value="' . $value . '"' . $plat . '>' . $value . '</option>' . "\n";
}
?>
</select>

<input type="submit" name="submit" id="submit" value="Filter" /></div>
</form>

but now i need to use the current value in the url string

so if i select option value "test" and press the filter button i would want to create a url like .......php?title=dah&amp;category=dee&amp;info="test" but i cannot for the love of me get the value to appear here. i tried

<form id="filter" action="price_results.php?title=<?php echo urlencode($title)?>&amp;category=<?php echo $category?>&amp;info=<?php echo $_POST['platform']?>" method="POST">

but it didnt work :(

any ideas
Thanks
Luke

LJackson
Sep 16th, 2009, 05:18 PM
ok


<form id="filter" action="price_results.php?title=<?php echo urlencode($title)?>&amp;category=<?php echo $category?>&amp;info=<?php echo $_POST['platform']?>" method="POST">

does work but you have to submit the form twice for the correct data to show :(

effpeetee
Sep 16th, 2009, 05:44 PM
There is some 'Form' help here (http://www.exitfegs.co.uk/Sources.html). Type Form into the search box.

Also here is one page from that (http://www.contactmeform.com/).

I cannot help you myself. I have never coded a form before.

Frank

LJackson
Sep 16th, 2009, 05:49 PM
thanks for the links mate, will check them out :)

LJackson
Sep 16th, 2009, 09:19 PM
Have just checked out the links and unfortunatly the information is not specific to what i need :(

but thanks for the useful links have bookmarked them for future use :)

anyone have any ideas as to why i am needing to submit the form twice to get the correct value passed to the url???

thanks
Luke

LJackson
Sep 16th, 2009, 11:04 PM
ok im getting somewhere, just dont know where :D

by adding these lines:

<?php
$_SESSION['platform'] = $_POST['platform'];
$platform_info = $_SESSION['platform'];
print $platform_info;
?>



just after the select closing tab like so

//fill the list box with platform array
foreach($array2 as $value)
{
$plat = (isset($_POST['platform']) && $_POST['platform'] == $value) ? ' selected' : '';
echo '<option value="' . $value . '"' . $plat . '>' . $value . '</option>' . "\n";
}

?>
</select>
<?php
$_SESSION['platform'] = $_POST['platform'];
$platform_info = $_SESSION['platform'];
print $platform_info;
?>
<input type="submit" name="submit" id="submit" value="Filter" /></div>
</form>


its printing out the current value of the listbox so i have tried using the varible in my url like so:

<form id="filter" action="price_results.php?title=<?php echo urlencode($title)?>&amp;category=<?php echo $category?>&amp;info=<?php echo $platform_info?>" method="POST">

but i was getting some very strange errors:


Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

and then when i changed my list value i got some info about being unable to send header to output or something so i added ob_start and ob_flush_end to the begining and end of my code.

now im getting

Warning: session_start() [function.session-start]: Node no longer exists

any ideas what i need to do?

here is my full code

ob_start();
session_start();
$_SESSION['page'] = "results";
$_SESSION['page_category'] = "results";

<!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" />
<link rel="stylesheet" type="text/css" href="css/rating.css"/>
<link rel="stylesheet" type="text/css" href="css/general_css.css"/>
<link rel="stylesheet" type="text/css" href="css/menu.css" />
<link rel="stylesheet" type="text/css" href="css/results.css" />
<title><?php print"Kernow Connect - $searchterm";?></title>
</head>

<body>

<form id="filter" action="price_results.php?title=<?php echo urlencode($title)?>&amp;category=<?php echo $category?>&amp;info=<?php echo $platform_info?>" method="POST">

<div>
<label for="cat_select"><strong>Platform: </strong></label>
<select id="cat_select" name="platform">

<?php
//fill the list box with platform array
foreach($array2 as $value)
{
$plat = (isset($_POST['platform']) && $_POST['platform'] == $value) ? ' selected' : '';
echo '<option value="' . $value . '"' . $plat . '>' . $value . '</option>' . "\n";
}

?>
</select>
<?php
$_SESSION['platform'] = $_POST['platform'];
$platform_info = $_SESSION['platform'];
print $platform_info;
?>
<input type="submit" name="submit" id="submit" value="Filter" /></div>
</form>

</body>
</html>
<?php ob_end_flush();?>


any help would be appreciated :)
thanks