News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Custom profile fields (core feature) - Checkbox error

Started by pellejones, March 24, 2013, 11:58:39 AM

Previous topic - Next topic

pellejones

Hi!

I have activated the core Feature "Custom Profile Fields" and want to use the option checkbox. To quote the SMF site: "Checkbox - Checkboxes are just like the boxes you saw on the previous page, with the standard fields.  Members may check multiple checkboxes.".
So I should get three rows and a [More] option at the end, but I only get the one checkbox and nothing else. It displays the number 0 if unchecked or 1 if checked, on profiles.

Looking through Admin.template.php I found this code that manages that area. I cant figure out what is wrong or how to get rows to show for the checkbox.


<fieldset>
<legend>', $txt['custom_edit_input'], '</legend>
<dl class="settings">
<dt>
<strong>', $txt['custom_edit_picktype'], ':</strong>
</dt>
<dd>
<select name="field_type" id="field_type" onchange="updateInputBoxes();">
<option value="text"', $context['field']['type'] == 'text' ? ' selected="selected"' : '', '>', $txt['custom_profile_type_text'], '</option>
<option value="textarea"', $context['field']['type'] == 'textarea' ? ' selected="selected"' : '', '>', $txt['custom_profile_type_textarea'], '</option>
<option value="select"', $context['field']['type'] == 'select' ? ' selected="selected"' : '', '>', $txt['custom_profile_type_select'], '</option>
<option value="radio"', $context['field']['type'] == 'radio' ? ' selected="selected"' : '', '>', $txt['custom_profile_type_radio'], '</option>
<option value="check"', $context['field']['type'] == 'check' ? ' selected="selected"' : '', '>', $txt['custom_profile_type_check'], '</option>
</select>
</dd>
<dt id="max_length_dt">
<strong>', $txt['custom_edit_max_length'], ':</strong><br />
<span class="smalltext">', $txt['custom_edit_max_length_desc'], '</span>
</dt>
<dd id="max_length_dd">
<input type="text" name="max_length" value="', $context['field']['max_length'], '" size="7" maxlength="6" class="input_text" />
</dd>
<dt id="dimension_dt">
<strong>', $txt['custom_edit_dimension'], ':</strong>
</dt>
<dd id="dimension_dd">
<strong>', $txt['custom_edit_dimension_row'], ':</strong> <input type="text" name="rows" value="', $context['field']['rows'], '" size="5" maxlength="3" class="input_text" />
<strong>', $txt['custom_edit_dimension_col'], ':</strong> <input type="text" name="cols" value="', $context['field']['cols'], '" size="5" maxlength="3" class="input_text" />
</dd>
<dt id="bbc_dt">
<strong>', $txt['custom_edit_bbc'], '</strong>
</dt>
<dd id="bbc_dd">
<input type="checkbox" name="bbc"', $context['field']['bbc'] ? ' checked="checked"' : '', ' class="input_check" />
</dd>
<dt id="options_dt">
<a href="', $scripturl, '?action=helpadmin;help=customoptions" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" class="icon" alt="', $txt['help'], '" /></a>
<strong>', $txt['custom_edit_options'], ':</strong><br />
<span class="smalltext">', $txt['custom_edit_options_desc'], '</span>
</dt>
<dd id="options_dd">
<div>';

foreach ($context['field']['options'] as $k => $option)
{
echo '
', $k == 0 ? '' : '<br />', '<input type="radio" name="default_select" value="', $k, '"', $context['field']['default_select'] == $option ? ' checked="checked"' : '', ' class="input_radio" /><input type="text" name="select_option[', $k, ']" value="', $option, '" class="input_text" />';
}
echo '
<span id="addopt"></span>
[<a href="" onclick="addOption(); return false;">', $txt['custom_edit_options_more'], '</a>]
</div>
</dd>
<dt id="default_dt">
<strong>', $txt['custom_edit_default'], ':</strong>
</dt>
<dd id="default_dd">
<input type="checkbox" name="default_check"', $context['field']['default_check'] ? ' checked="checked"' : '', ' class="input_check" />
</dd>
</dl>
</fieldset>



I know that this part of the code adds the rows for the radio-thing but I have no idea how to transfer that to checkboxes.

foreach ($context['field']['options'] as $k => $option)
{
echo '
', $k == 0 ? '' : '<br />', '<input type="radio" name="default_select" value="', $k, '"', $context['field']['default_select'] == $option ? ' checked="checked"' : '', ' class="input_radio" /><input type="text" name="select_option[', $k, ']" value="', $option, '" class="input_text" />';
}


Any help would be fantastic!

Arantor

QuoteSo I should get three rows and a [More] option at the end, but I only get the one checkbox and nothing else. It displays the number 0 if unchecked or 1 if checked, on profiles.

That's right, that's what you're supposed to get. Checkbox is simply that: a single checkbox for yes/no.

If you're hoping for a 'select multiple items' option, there isn't one.

pellejones

No. You are wrong.

"Checkbox - Checkboxes are just like the boxes you saw on the previous page, with the standard fields.  Members may check multiple checkboxes."
Cited from this page: http://docs.simplemachines.org/index.php?topic=1084.0

Also, I only get the checkbox! No text field next to it. Ergo, it serves no function at all.

Arantor

The manual's wrong. It has never worked like that, not since it was first implemented several years ago. You're pretty much the first person to notice.

The code doesn't even support multiple selection. I know this for a fact because when I wrote the helpdesk used on this site, we started off using a similar template for the custom fields - and I specifically had to add a ton of code to make multiple selection boxes work. Including the UI code.

I'm telling you: it doesn't work the way you want, and I don't care what the manual tells you, because I know the manual's wrong.

QuoteNo text field next to it. Ergo, it serves no function at all.

Oh, it serves a function. On this site, go into Profile > Look and Layout Preferences, look at the last two options. They're checkbox options.

pellejones

Ah! I stand corrected then :)

I cant go to look and layout here :/

Arantor

Ah, when you get to 10 posts, you will. Anyway, it looks like this.

Sometimes you just want a yes/no option and one of them, and this is what it's for. Doing multi-selection in the current code would be... extremely unreliable.

pellejones

Ok!

Thanks for all the help.

So I guess what I want is this then:

This is how I want it!


This is how it is now


This is how I get it done now



This is how I would like to do it

Arantor

There's several things here.

First up: using images is fine, but you won't see the images themselves in the admin area. Seems to me you just need to use radio buttons for each medal you want to show - which seems to be what you have?

Secondly, positioning them horizontally as opposed to vertically should be doable by editing the theme's definition of .custom_fields_above_signature in its index.css. Exactly what that will be will be specific to the theme and I don't recognise your theme, so I can't tell you exactly what to change, only that it will be there that needs changing.

pellejones

QuoteSeems to me you just need to use radio buttons for each medal you want to show - which seems to be what you have?

Yeah exactly! So now I just need to figure out if there is a way to make the pictures show instead of the code?

I will look into that positioning. Thank you.

This is from index.css
.custom_fields_above_signature
{
width: 98%;
clear: right;
padding: 1em 0 3px 0;
border-top: 1px solid #aaa;
line-height: 1.4em;
font-size: 0.85em;
}

Arantor

Doesn't the picture show to users? It should IIRC...

pellejones

I'll repost this.

.custom_fields_above_signature
{
width: 98%;
clear: right;
padding: 1em 0 3px 0;
border-top: 1px solid #aaa;
line-height: 1.4em;
font-size: 0.85em;
}



Only admins can add the picture. And the picture will show on the forum on topics of course, but I would like to see pictures when I select what to use, instead of the BB-code.

Arantor

I actually really wanted a link to see it in context, rather than just the snippet of code in question.

As for formatting, this is weird. I can only assume it's done for performance because bbc parsing is horrendously expensive. (It's the single largest thing in SMF, weighing in at 1500 lines)

But to display in-thread using bbc, edit Load.php

foreach ($context['display_fields'] as $custom)
{
if (empty($custom['title']) || empty($profile['options'][$custom['colname']]))
continue;

$value = $profile['options'][$custom['colname']];

// BBC?
if ($custom['bbc'])
$value = parse_bbc($value);


That last if statement would become:
if ($custom['bbc'] || $custom['type'] == 'radio')


For editing the profile, you'll need to edit this part of Profile.php:
elseif ($row['field_type'] == 'radio')
{
$input_html = '<fieldset>';
$options = explode(',', $row['field_options']);
foreach ($options as $k => $v)
{
$true = (!$exists && $row['default_value'] == $v) || $value == $v;
$input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" class="input_radio" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '" ' . ($true ? 'checked="checked"' : '') . '>' . $v . '</label><br />';
if ($true)
$output_html = $v;
}
$input_html .= '</fieldset>';
}


and replace with:
elseif ($row['field_type'] == 'radio')
{
$input_html = '<fieldset>';
$options = explode(',', $row['field_options']);
foreach ($options as $k => $v)
{
$true = (!$exists && $row['default_value'] == $v) || $value == $v;
$input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" class="input_radio" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '" ' . ($true ? 'checked="checked"' : '') . '>' . parse_bbc($v) . '</label><br />';
if ($true)
$output_html = parse_bbc($v);
}
$input_html .= '</fieldset>';
}

pellejones

#12
OK I'll give it a go.

What did you need? You said the snipped of code was not enough..

OK! I got it working :)

Now for another question. what If I want to make a line break in one of the pictures. I just removed the <li> from all the templates that have custom fields. Is is possible to define <li> as a custom field?

Solved it!

Arantor

Quote from: Arantor on March 24, 2013, 01:11:34 PM
I actually really wanted a link to see it in context, rather than just the snippet of code in question.

pellejones

The two custom pictures I made above shows it in context. I have solved the row problem by removing the <li> in the code.

Arantor

Which breaks HTML validation and will have a possibly negative effect on search engines, awesome.

There was a reason I wanted to see it in context, to give you the correct styling changes for your theme, but if you're happy with how you have it, even with its problems, that's fine too.

(I can't change CSS in a *picture* to see what will work best, whereas I can if I can see the actual page.)

pellejones

So removing the <li> is not the way to do it?

I can post the code from the site, and I can post the template.

Arantor

No, removing the <li> is not the way to do it.

And no, staring at the code is not what I need, I need to see it in action so I can manipulate it in the browser to figure out what the code should be - CSS is not my strongpoint.

But if you can't give me an active link to a thread, I can't help, sorry.

pellejones


Arantor

Looks like the CSS changes should be:

.custom_fields_above_signature
{
width: 98%;
clear: right;
padding: 1em 0 3px 0;
border-top: 1px solid #aaa;
line-height: 1.4em;
font-size: 0.85em;
}

.custom_fields_above_signature li
{
float: left;
}

.signature
{
clear: both !important;
}

pellejones

OK that worked perfectly!

Now for a different question. Only forum Admins can actually change custom fields when set to "admin change". I want semi-admins (own defined group that has almost all permissions) to be able to assign custom profile field stuff to users. But in the permissions settings for user groups, this is not available to select :( I can't assign the permission to do that.

Arantor

Because it's another thing that SMF can't do. And adding that isn't a quick code change, it's a fairly large overhaul.

Advertisement: