Jump to content

Post multi select box selections to select box on second page. Help Please!


Guest tetzloff

Recommended Posts

Guest tetzloff
Ok, this one might be simpler for all of you to figure out. I am fairly new to php and I am pulling my hair out on this one. I will include my code and a link to the active forms I have now. (slimmed down and over-simplified of course )

My Objective:
Basically what I am creating are online property profile sheets for realtors that they can use to fill out information about a property they are going to sell. These need to be saved on the client computer and re-edited without a database interaction. I have almost everything figured out except for one thing, writing multiple select boxe selections and non selected items to another select box on the next page. Here is what I need to be able to do:

A. Select items in the multiple select box on the form page 1. then click the save and continue button.
B. Write those selections from the previous page to an identicle multiple select box on form page 2, which I have done, but it does not keep the items that you did not select which is a problem because, this form on page 2 is meant to be saved via File --> Save As for later editing. This is easy with text fields because you can just post the text that is typed in to them to the value of the text input field. But I cannot for the life of me figure out how to do this with these multiple select boxes or select boxes.

Here is a link to my current semi-working form: [url=http://tetzloff.netfirms.com/postSelections/origionalForm.php]http://tetzloff.netfirms.com/postSelections/origionalForm.php[/url]

[b][size=10pt]Here is the code for Form Page 1:[/size][/b]

[code]
<html>
<head>
<title>Origional Form</title>
</head>
<body>
<form action="secondForm.php" method="post">
<?php

$heating = array(First =>'First', Second =>'Second', Third =>'Third', Fourth =>'Fourth');

// Make Heating MultiSelect
echo '<select size="4" name="heating[]" multiple="multiple" style="margin: 5px 0pt; width: 175px;">';
foreach ($heating as $key => $value) {
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>';

?>
<br>
<input type="submit" value="please work">
</form>

</body>
</html>
[/code]


[b][size=10pt]Here is the code for Form Page 2:[/size][/b]

[code]
<html>
<head>
<title>Second Form</title>
</head>
<body>
<form action="origionalForm.php" method="post">

<?php

$heating = array(First =>'First', Second =>'Second', Third =>'Third', Fourth =>'Fourth');

echo '<select size="4" name="heating[]" multiple="multiple" style="margin: 5px 0pt; width: 175px;">';
    if (isset($_POST['heating']) && is_array($_POST['heating']) &&  !empty($_POST['heating']))
    {
        foreach($_POST['heating'] as $value)
        {
        echo "<option value=\"$value\" selected=\"selected\">$value</option>\n";
        }
    }
    else
    {
    echo "<option value=\"$value\">$value</option>\n";
    }

echo '</select>';
?>

<br>
<input type="submit" value="please work">
</form>

</body>
</html>
[/code]

Thank you in advance for your help. I greatly appreciate it.

-Tyler
If you cant do another  db call to see what all of the values of your select box should be, (my first choice). Then include a hidden form field that has a comma seperated list of your select box items. You can either populate it will all values when the page is generated, or have an on submit function that puts non-selected items into it.
Guest tetzloff
Thank you for the quick post. I do not really want to use a database because each user cannot see the others data. So I wouldn’t want to have to create login accounts or lock it down. This is why they would need to save it on their respective computers.

I gave your second solution a shot, but I could not figure out how to do it. Do you think you could help me out with an example.

If anyone has any suggestions, examples or further explanations please post.

..and again thank you in advance.

-Tyler
Guest tetzloff
I got it all figured out:  :)

[size=10pt][b]Here is the solution:[/b][/size]

[code]
<html>
<head>
<title>form</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php

$heating = array('First' =>'First', 'Second' =>'Second', 'Third' =>'Third', 'Fourth' =>'Fourth');

// Make Heating MultiSelect
echo '<select size="4" name="heating[]" multiple="multiple" style="margin: 5px 0pt; width: 175px;">';
foreach ($heating as $key => $value) {
        echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>';

?>
<br>
<input type="submit" value="please work">
</form>

<?php
echo '<select size="4" name="heating[]" multiple="multiple" style="margin: 5px 0pt; width: 175px;">';
    if (!empty($_POST['heating']) && is_array($_POST['heating'])){
        foreach($heating as $key => $value){
                if(in_array($key, $_POST['heating'])){
                        echo "<option value=\"$value\" selected=\"selected\">$value</option>\n";
                }else{
                        echo "<option value=\"$value\">$value</option>\n";                   
                }
        }
    }
echo '</select>';
?>

</body>
</html>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.