|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
smartt Smarty Rookie
Joined: 24 Jul 2003 Posts: 10 Location: Dresden, Germany
|
Posted: Thu Aug 07, 2003 8:34 am Post subject: multiple select doesn´t work |
|
|
i try to access the values of a multiple select field in php, but that doesn´t work:
my php, which assigns the associative array looks like this:
$sql="SELECT * FROM laender ORDER BY name ASC";
$laenderrs=$conn->select($sql);
$smarty->assign("laenderrs", $laenderrs);
my tpl looks like this:
<select name="laender[]" size="5" multiple>
{foreach from=$laenderrs item=land}
<option value="{$land.id}">{$land.name}</option>
{/foreach}
</select>
the html-output looks normal:
<select name="laender[]" size="5" multiple>
<option value="3">Botswana</option>
<option value="1">Namibia</option>
<option value="2">Südafrika</option>
<option value="4">Zimbabwe</option> </select>
if i try to access $_POST[laender] in a foreach loop like this:
foreach ($_POST[laender] as $key=>$value){
echo "$key, $value";
}
i get the following error:
Warning: Invalid argument supplied for foreach() in d:\htdocs\admin.php on line 29
if i try this without smarty, it works fine...what is wrong? |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Thu Aug 07, 2003 12:04 pm Post subject: |
|
|
Worked fine when I tried it but first use $_POST['laender'] because a string not inside quotes will thorw a constant error and also foreach on a normal array just use foreach($array as $value) then the select value field was displayed for me. _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|