bradkenyon Posted February 21, 2007 Share Posted February 21, 2007 I am trying to display multiple checkboxes, using an object oriented form. I have all the values within the array flabels. I need to tweak this foreach loop to show each one, right now it only displays one checkbox, well...when the foreach loop is commented out, when it is not commented out, the page does not display, the foreach is tripping up the page. if (defined("ACCT_XFIELD1")) $f->add_element(array("type"=>"checkbox", "value"=>$flabels, "name"=>"D_xfield1", "multiple"=>true)); When the foreach is commented out, it displays only one checkbox, here is the source code of that one box that displays: <input type="checkbox" name="D_xfield1[]" value="Array" /> Below is the entire page which I need to fix the foreach loop to display the multiple checkboxes. I appreciate the help. <?PHP function Create_Account_Register_Form ($fid='') { $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) { //storing all the different checkboxes within the array $flabels foreach ($flabels as $value) { printf('<input type="checkbox" name="D_xfield1[]" value="%s" /> %s<br />',$value,$value); } $f = new form; if (defined("ACCT_USERNAME")) $f->ae(DF_username($_POST['D_username'])); if (defined("ACCT_PASSWORD")) $f->ae(DF_password($_POST['D_password'])); if (defined("ACCT_FIRSTNAME")) $f->ae(DF_firstname($_POST['D_firstname'])); if (defined("ACCT_LASTNAME")) $f->ae(DF_lastname($_POST['D_lastname'])); if (defined("ACCT_TITLE")) $f->ae(DF_title($_POST['D_title'])); if (defined("ACCT_ORGANIZATION")) $f->ae(DF_organization($_POST['D_organization'])); if (defined("ACCT_ADDRESS1")) $f->ae(DF_address1($_POST['D_address1'])); if (defined("ACCT_ADDRESS2")) $f->ae(DF_address2($_POST['D_address2'])); if (defined("ACCT_CITY")) $f->ae(DF_city($_POST['D_city'])); if (defined("ACCT_STATEPROV")) $f->ae(DF_stateprov($_POST['D_stateprov'])); if (defined("ACCT_COUNTRY")) $f->ae(DF_country($_POST['D_country'])); if (defined("ACCT_POSTCODE")) $f->ae(DF_postalcode($_POST['D_postcode'])); if (defined("ACCT_TELEPHONE")) $f->ae(DF_telephone($_POST['D_telephone'])); if (defined("ACCT_FAX")) $f->ae(DF_fax($_POST['D_fax'])); if (defined("ACCT_EMAIL")) $f->ae(DF_email($_POST['D_email'])); //if (defined("ACCT_XFIELD1")) $f->ae(DF_xfield1($_POST['D_xfield1'])); if (defined("ACCT_XFIELD1")) $f->add_element(array("type"=>"checkbox", "value"=>$flabels, "name"=>"D_xfield1", "multiple"=>true)); $f->ae(array("type"=>"hidden", "name"=>"D_fid", "value"=>$fid)); $f->ae(DF_submit('D_submit','REGISTER')); return $f; } ?> Quote Link to comment Share on other sites More sharing options...
joquius Posted February 21, 2007 Share Posted February 21, 2007 foreach ($flabels as $value) { //storing all the different checkboxes within the array $flabels foreach ($flabels as $value) { printf('<input type="checkbox" name="D_xfield1[]" value="%s" /> %s<br />',$value,$value); } I don't really get this, why are you looping this twice? Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted February 21, 2007 Author Share Posted February 21, 2007 oops. it outputs it now, but displays it at the top of the page, and not where i have the tag placed: <tr> <td align="right"><b>Areas of Interest:</b></td><td>{Q_ACCT_F_X1}</td> </tr> i wonder why its not displaying where it should be, i attached a screen shot of what im talking about. <?PHP /* * DYNAMO V5 : QUADSIMIA * $Id: register_form.inc,v 1.1 2005/12/10 10:59:36 scottg Exp $ */ function Create_Account_Register_Form ($fid='') { $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" ); //storing all the different checkboxes within the array $flabels foreach ($flabels as $value) { printf('<input type="checkbox" name="D_xfield1[]" value="%s" /> %s<br />',$value,$value); } $f = new form; if (defined("ACCT_USERNAME")) $f->ae(DF_username($_POST['D_username'])); if (defined("ACCT_PASSWORD")) $f->ae(DF_password($_POST['D_password'])); if (defined("ACCT_FIRSTNAME")) $f->ae(DF_firstname($_POST['D_firstname'])); if (defined("ACCT_LASTNAME")) $f->ae(DF_lastname($_POST['D_lastname'])); if (defined("ACCT_TITLE")) $f->ae(DF_title($_POST['D_title'])); if (defined("ACCT_ORGANIZATION")) $f->ae(DF_organization($_POST['D_organization'])); if (defined("ACCT_ADDRESS1")) $f->ae(DF_address1($_POST['D_address1'])); if (defined("ACCT_ADDRESS2")) $f->ae(DF_address2($_POST['D_address2'])); if (defined("ACCT_CITY")) $f->ae(DF_city($_POST['D_city'])); if (defined("ACCT_STATEPROV")) $f->ae(DF_stateprov($_POST['D_stateprov'])); if (defined("ACCT_COUNTRY")) $f->ae(DF_country($_POST['D_country'])); if (defined("ACCT_POSTCODE")) $f->ae(DF_postalcode($_POST['D_postcode'])); if (defined("ACCT_TELEPHONE")) $f->ae(DF_telephone($_POST['D_telephone'])); if (defined("ACCT_FAX")) $f->ae(DF_fax($_POST['D_fax'])); if (defined("ACCT_EMAIL")) $f->ae(DF_email($_POST['D_email'])); //if (defined("ACCT_XFIELD1")) $f->ae(DF_xfield1($_POST['D_xfield1'])); if (defined("ACCT_XFIELD1")) $f->add_element(array("type"=>"checkbox", "value"=>$flabels, "name"=>"D_xfield1", "multiple"=>true)); /* for ($i=1;$i<=10;$i++) { $xfvar = sprintf("D_xfield%d",$i); $xfunc = sprintf("DF_xfield%d",$i); if (defined("ACCT_XFIELD".$i)) $f->ae(call_user_func($xfunc,$_POST[$xfvar])); } */ $f->ae(array("type"=>"hidden", "name"=>"D_fid", "value"=>$fid)); $f->ae(DF_submit('D_submit','REGISTER')); return $f; } ?> [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
joquius Posted February 21, 2007 Share Posted February 21, 2007 printf() is an output function, it will output wherever it is Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted February 21, 2007 Author Share Posted February 21, 2007 foreach ($flabels as $value) { sprintf('<input type="checkbox" name="D_xfield1[]" value="%s" /> %s<br />',$value,$value); } it doesn't display the list of checkboxes like it did in the image i supplied previous. but it still just displays one checkbox, next to "Areas of Interest:", which the code for that is <input type="checkbox" name="D_xfield1[]" value="Array" /> Quote Link to comment Share on other sites More sharing options...
joquius Posted February 21, 2007 Share Posted February 21, 2007 you need to: 1. let the function define that tag OR 2. replace the tag with the output of the function Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted February 21, 2007 Author Share Posted February 21, 2007 foreach ($flabels as $value) { sprintf('<input type="checkbox" name="D_xfield1[]" value="%s" /> %s<br />',$value,$value); } the below is fine? i just can't get the for loop right, what should it look like? if (defined("ACCT_XFIELD1")) $f->add_element(array("type"=>"checkbox", "value"=>$flabels, "name"=>"D_xfield1", "multiple"=>true)); I really appreciate the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.