jadesource Posted July 26, 2014 Share Posted July 26, 2014 Hi I'm totally green when it comes to php, but am learning it the hard way. Any help is appreciated. I have a form the currenty uses a custom taxonomy but it has a text field, and I want it to call and list the taxonomy items with checkboxes so instead of entering words the visitor can just multiple check off the taxonomies that relate to them. It's a job board, this is the job skill part that relates to their expertise. There is a job category in the form, and I tried to use the syntax to get the taxonomy and implode it but I really don't know what I'm doing. See the "skills" item? I want to make that a bunch of checkboxes to allow selection the the pre defined resume_skills taxonomy. http://outsourcing.jadesource.com/submit-resume-free/ Any help would be great, and I'm not sure what code I need to put in here. Mark Quote Link to comment https://forums.phpfreaks.com/topic/290117-need-to-change-array-to-checkboxes-in-form/ Share on other sites More sharing options...
ginerjm Posted July 26, 2014 Share Posted July 26, 2014 Checkboxes work by assigning ALL of them the same 'name=' attribute. Your html for a checkbox would look like: <input type='checkbox' name='skills[]' value='1'><label> Skill 1</label> <input type='checkbox' name='skills[]' value='2'><label> Skill 2</label> Create as many of these as you need with each having a unique value attribute and label. Then in your php code you will create a loop to go thru the returned $_POST elements that will be in the 'name' index in an array. $invalid_skill = false; $have_skills=false; foreach ($_POST['skill'] as $skill) { if (!in_array($skill,array(1,2,3,4,5))) { $invalid_skill=true; } else { $have_skills = true; } } if (!$invalid_skill) { $err_msg = "You have an invalid skill";// user hacked the form and produced something wrong } if (!$have_skills) { $err_msg = "You must provide a skill"; } Of course you can use the literal value of the skills in the value clauses instead of a number, but I think this gives you something to work with. Hope to see your code attempt soon! Quote Link to comment https://forums.phpfreaks.com/topic/290117-need-to-change-array-to-checkboxes-in-form/#findComment-1486174 Share on other sites More sharing options...
davidannis Posted July 26, 2014 Share Posted July 26, 2014 Gingerjm gave you an excellent strart. I think that you will should store a default set of the skills in a database (you could hardcode them in the form but I would recommend against that) and produce the initial checkboxes from your list rather than from POST data. You'll still need a text input because you can't possibly anticipate everything. Quote Link to comment https://forums.phpfreaks.com/topic/290117-need-to-change-array-to-checkboxes-in-form/#findComment-1486175 Share on other sites More sharing options...
ginerjm Posted July 26, 2014 Share Posted July 26, 2014 David - I wasn't suggesting that the initial checkboxes be created from POST data. As I showed - they are created manually. They could be created via a query that pulls down 'value' items and 'literal' skill names to be used in the html, but I left that to the OP's imagination and skill level 1 Quote Link to comment https://forums.phpfreaks.com/topic/290117-need-to-change-array-to-checkboxes-in-form/#findComment-1486176 Share on other sites More sharing options...
davidannis Posted July 27, 2014 Share Posted July 27, 2014 (edited) David - I wasn't suggesting that the initial checkboxes be created from POST data. As I showed - they are created manually. They could be created via a query that pulls down 'value' items and 'literal' skill names to be used in the html, but I left that to the OP's imagination and skill level Sorry, I missed the manual creation. I believe that whether manually created or in a database, for the OPs purpose there needs to be an other box with the ability to put in freeform text if the box is checked. There is no way to compile a complete list of skills and keep it up to date. Edited July 27, 2014 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/290117-need-to-change-array-to-checkboxes-in-form/#findComment-1486271 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.