Jump to content

for loop


bradkenyon

Recommended Posts

need to fix the foreach loop to output the checkboxes.

 

right now it only outputs one checkbox, this is the code it spits out for the only checkbox that it displays when the foreach loop is commented out, if it isn't - the page trips up and does not display anything, so it is something with the foreach loop:

<input type="checkbox" name="D_xfield1[]" value="Array" />

 

below is the array and foreach loop i have, but it's not right,

$flabels = array (
        "Childrens Area"=>"Childrens Area",
        "Retail Sales"=>"Retail Sales",
        "Info Booth"=>"Info Booth",
        "Beer/Wine Pouring"=>"Beer/Wine Pouring",
        "Ticket Takers"=>"Ticket Takers",
        "Hospitality"=>"Hospitality",
        "Setup"=>"Setup",
        "Marketing"=>"Marketing",
        "Stages"=>"Stages",
        "Take down"=>"Take down",
        "Security"=>"Security",
        "Cleanup"=>"Cleanup",
        "Cashier"=>"Cashier",
        "Volunteer Check-In"=>"Volunteer Check-In",
        "Volunteer Booth"=>"Volunteer Booth",
        "Artist Merchandise"=>"Artist Merchandise",
        "GAIF Food Booth"=>"GAIF Food Booth",
        "EMS"=>"EMS"
    );

foreach ($flabels as $value) {
   		sprintf('<input type="checkbox" name="D_xfield1[]" value=$flabels /> $flabels<br />');
}

 

below is what adds the element to the template in which i use to call the multiple checkboxes.

if (defined("ACCT_XFIELD1")) $f->add_element(array("type"=>"checkbox",
								 "value"=>$flabels,
								 "name"=>"D_xfield1",
								 "multiple"=>true));

 

I really appreciate the help!

Link to comment
https://forums.phpfreaks.com/topic/39639-for-loop/
Share on other sites

<?php

$flabels = array (
        "Childrens Area"=>"Childrens Area",
        "Retail Sales"=>"Retail Sales",
        "Info Booth"=>"Info Booth",
        "Beer/Wine Pouring"=>"Beer/Wine Pouring",
        "Ticket Takers"=>"Ticket Takers",
        "Hospitality"=>"Hospitality",
        "Setup"=>"Setup",
        "Marketing"=>"Marketing",
        "Stages"=>"Stages",
        "Take down"=>"Take down",
        "Security"=>"Security",
        "Cleanup"=>"Cleanup",
        "Cashier"=>"Cashier",
        "Volunteer Check-In"=>"Volunteer Check-In",
        "Volunteer Booth"=>"Volunteer Booth",
        "Artist Merchandise"=>"Artist Merchandise",
        "GAIF Food Booth"=>"GAIF Food Booth",
        "EMS"=>"EMS"
    );

foreach ($flabels as $key => $val) {
   		echo'<input type="checkbox" name="D_xfield1[]" value="$key" /> '.$val.'<br />';
}
   		?>

Link to comment
https://forums.phpfreaks.com/topic/39639-for-loop/#findComment-191329
Share on other sites

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.