Re: parsing select multiple="multiple"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




tamouse mailing lists wrote:
>I hate arrays. :D
Here's a small snippet showing how it works, I hope:

foreach ($DPRpriority as $item => $value) {
   echo "<li> ".$item.": ".$value['name']." selected:
".$value['selected']." </li>\n";
}

Question 1: when did we have to add [] to a <input> name to turn it into an array?

<input type="checkbox" name="DPRlocationdetails[]" value="Unknown">

According to phpinfo() it still comes out as $_POST['DPRlocationdetails'] without [].

Are the [] necessary?
----------------------------------------------
Question 2:
I was looking at some code in the Manual, where someone used isset and is_array.

How necessary is if(isset($_POST['DPRlocationdetails']))

and then to use: if(is_array($_POST['DPRlocationdetails']))

That seems like over kill?
----------------------------------------------
Question 3:

My code works, perfectly. In this case, I decided to attack some check-boxes first. The resulting function will work for <select multiple> too..

Does anyone see me doing something wrong in my code below?

My questions are:

Is this the only way to pass "Unknown", "Family Home" or "Apartment" into the function?

Is this correct?

---- if ($_POST['DPRlocationdetails'] == "Unknown")

Somebody once told me I had to do it this way?

---- if ("Unknown" == $_POST['DPRlocationdetails'])

John

--------------------snip---------------------------

<form action="foo.php" id="DPRform" method="post"><input value="Update" type="submit"> <input type="checkbox" name="DPRlocationdetails[]" value="Unknown" <?php filter_value($_POST['DPRlocationdetails'],"Unknown"); ?>> Unknown <input type="checkbox" name="DPRlocationdetails[]" value="Family Home" <?php filter_value($_POST['DPRlocationdetails'],"Family Home"); ?>> Family Home <input type="checkbox" name="DPRlocationdetails[]" value="Apartment" <?php filter_value($_POST['DPRlocationdetails'],"Apartment"); ?>> Apartment
</form>

<?php
function filter_value($tofilter,$tofind) {
foreach($tofilter as $value){
    if ($value == $tofind) echo "checked";
    }
}
?>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux