2 of 2
2
Hacking the member templates to allow radio btns and checkboxes for custom profile fields
Posted: 20 September 2007 03:33 PM   [ Ignore ]   [ # 19 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  571
Joined  10-14-2005

I found a workaround to allow me to display field separators by adding another ‘field type’ of ‘none’ in the same format as my hack to add checkboxes and radio buttons. The ‘none’ field type returns a seperator which includes a sub title for that area of the form. smile

 Signature 

Nathan Pitman

Nine Four Ltd - a member of the EEPro Network

Profile
 
 
Posted: 16 October 2007 07:44 PM   [ Ignore ]   [ # 20 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1735
Joined  03-26-2006

Hi, thanks for this.

First of all, I’m trying this is a standalone registration form and having an issue with a single field that needs multiple checkboxes. Not sure how to properly render checkboxes for one field other than giving them all the same name - but only the last value is kept. My field ID for this field is m_field_id_11 - but your code (was reading the Wiki) shows this as the last step:

$checkboxes = array("m_field_id_1");
foreach (
$checkboxes as $checkbox_field)
{
    
if (!isset($_POST[$checkbox_field])) {
        $_POST[$checkbox_field]
= "n";
    
}
}


What exactly is that doing? Should I change that ‘m_field_id_1’ to ‘m_field_id_11’? And what if I have more than one field where that I’ve designated as checkbox?

The radio button seems to work fine (m_field_id_10 in my DB), and a field with a single checkbox seems to work fine (m_field_id_9), but I have 9 selections I need people to choose from (m_field_id_11). Here’s some sample code:

<label><input name="m_field_id_11" type="checkbox" value="whatever1" /> whatever1</label>
<
label><input name="m_field_id_11" type="checkbox" value="whatever2" /> whatever2</label>
<
label><input name="m_field_id_11" type="checkbox" value="whatever3" /> whatever3</label>


If I select ‘1’ and ‘3’ right now, only ‘3’ gets stored in the DB.

I guess I need to ask too: where am I storing the values whatever1, whatever2, and whatever3?

One last thing: You say “To add a field that will be used as a checkbox use the ‘text’ type” - does that mean text input or textarea?

 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 17 October 2007 10:42 AM   [ Ignore ]   [ # 21 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1735
Joined  03-26-2006

OK, I figured out the first part, I think. I need to add every field that has a type of ‘checkbox’. So my variable/array will look like:

$checkboxes = array("m_field_id_9,m_field_id_11");


because I currently have two checkbox fields. (Yes, I should have read this thread a little more carefully…)

The second part of my post is still a little fuzzy for me. Can I make a single field with type of ‘checkbox’ and store multiple values? For example, a field called “Interests” that has 3 possible choices. I assume the code would look like so:

<label><input name="m_field_id_11[]" type="checkbox" value="whatever1" /> whatever1</label>
<
label><input name="m_field_id_11[]" type="checkbox" value="whatever2" /> whatever2</label>
<
label><input name="m_field_id_11[]" type="checkbox" value="whatever3" /> whatever3</label>


OR: do all of the choices themselves (whatever1, whatever2, etc) need to be custom fields set to type ‘checkbox’? Which means my checkbox array would look more like this:

$checkboxes = array("m_field_id_9,m_field_id_11,m_field_id_12,m_field_id_13");


and the markup would look more like:

<label><input name="m_field_id_11" type="checkbox" value="whatever1" /> whatever1</label>
<
label><input name="m_field_id_12" type="checkbox" value="whatever2" /> whatever2</label>
<
label><input name="m_field_id_13" type="checkbox" value="whatever3" /> whatever3</label>


Just not sure which way I need to go with this, and I’m starting to think it’s the latter, because I’m not sure how you would populate the multiple checkbox choices in the first example, if they’re not pulling from the field name. Thanks for your help!

 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 17 October 2007 11:50 AM   [ Ignore ]   [ # 22 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1735
Joined  03-26-2006

If I use the first method “m_field_id_11[]” (with the brackets), check 2-3 checkboxes on my form, and use phpMyAdmin to view what gets stored in that field, it says “Array”. Is that correct behavior? If so…cool…I can store all my related values in one field - as long as I can figure out how then read that array. Anyone? I hear crickets in here smile.

 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 17 October 2007 12:11 PM   [ Ignore ]   [ # 23 ]  
Lab Assistant
RankRank
Total Posts:  169
Joined  09-19-2007

i’m listening…. this is going to be my weekend project.

Profile
 
 
Posted: 17 October 2007 06:25 PM   [ Ignore ]   [ # 24 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  571
Joined  10-14-2005

You are correct, the method I took was to have a seperate custom profile field for each checkbox. However if you have managed to store an array on the DB field you could pulling it out with raw PHP or the SQL Query module to see what it contains. Just do a ‘print_r($variable_name);’

smile

 Signature 

Nathan Pitman

Nine Four Ltd - a member of the EEPro Network

Profile
 
 
Posted: 17 October 2007 06:26 PM   [ Ignore ]   [ # 25 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  571
Joined  10-14-2005
latte02125 - 17 October 2007 12:11 PM

i’m listening…. this is going to be my weekend project.

If you do manage to get something up and running please post your results back here! smile

 Signature 

Nathan Pitman

Nine Four Ltd - a member of the EEPro Network

Profile
 
 
Posted: 17 October 2007 06:42 PM   [ Ignore ]   [ # 26 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1735
Joined  03-26-2006

I made each choice its own field. Just easier that way! Now this part of my project is done! Thanks for taking the time to document this hack.

 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 18 October 2007 05:33 AM   [ Ignore ]   [ # 27 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  571
Joined  10-14-2005

No worries, glad that it worked for you too! Here’s hoping that EE 2 might have these features built in! smile

 Signature 

Nathan Pitman

Nine Four Ltd - a member of the EEPro Network

Profile
 
 
Posted: 21 October 2007 08:16 AM   [ Ignore ]   [ # 28 ]  
Lab Assistant
RankRank
Total Posts:  169
Joined  09-19-2007

Thanks for this code!!! It’s just what I need. 

However, I have one small thing that is not working though. 

When the user goes to their profile to update their checkbox, the check/uncheck does not update the database.  I think there might be something to do with the m_field_id_1.  Do I need to change m_field_id_1 to match the m_field_name I gave this field the exp_member_fields table?

You can see the functionality yourself if you wish at: babybloomermagazine.com/magazine/

Again, thanks for this!
Michael

Profile
 
 
Posted: 27 November 2007 07:12 AM   [ Ignore ]   [ # 29 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  571
Joined  10-14-2005

Bit of an update on this thread. I just started using the ‘Solspace User Module’ and this is really worth checking out. It takes a huge amount of pain out of working with member features becuase you can do pretty much everything using standard EE templates. Woot!

 Signature 

Nathan Pitman

Nine Four Ltd - a member of the EEPro Network

Profile
 
 
Posted: 27 November 2007 08:48 AM   [ Ignore ]   [ # 30 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1735
Joined  03-26-2006

Right, I cannot wait to give that module a try. I thought that project died, but I’m glad to see that it has been released!

 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
   
2 of 2
2
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65026 Total Logged-in Users: 39
Total Topics: 82115 Total Anonymous Users: 17
Total Replies: 441304 Total Guests: 189
Total Posts: 523419    
Members ( View Memberlist )
Newest Members:  meenoiYang.JianuoioitsukiNathan HammondalexcigadamstaneckiLucas Mayscybermilltstitt