check boxes in custom profile fields wont uncheck

Started by 1MileCrash, February 12, 2006, 06:04:02 PM

Previous topic - Next topic

1MileCrash

I have three checkboxes for custom profile fields..

<td><b>Owned Tippmann 98 Models: </b></td>

<td><input type="checkbox" name="default_options[model98]" value="1"', @$context['member']['options']['model98'] ? ' checked="checked"' : '', ' class="check" /> - Model 98<br/>
<input type="checkbox" name="default_options[98custom]" value="1"', @$context['member']['options']['98custom'] ? ' checked="checked"' : '', ' class="check" /> - 98 Custom<br/>
<input type="checkbox" name="default_options[custompro]" value="1"', @$context['member']['options']['custompro'] ? ' checked="checked"' : '', ' class="check" /> - Custom Pro</td>
    </tr><tr>


and something is obviously wrong, becasue if i go into my profile (or anyone's) and check one of the boxes off, and save, then i cant uncheck it. Unchecking it, then saving the profile leaves it checked no matter what..
The only thing php can't do is tell you how much milk is left in the fridge.



kegobeer

Of course, that's how you've written the code!  You've preset the value of each checkbox to 1.  Get rid of value="1".
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

1MileCrash

now i have:

<tr>

<td><b>Owned Tippmann 98 Models: </b></td>

<td><input type="checkbox" name="default_options[model98]"', @$context['member']['options']['model98'] ? ' checked="checked"' : '', ' class="check" /> - Model 98<br/>
<input type="checkbox" name="default_options[98custom]"', @$context['member']['options']['98custom'] ? ' checked="checked"' : '', ' class="check" /> - 98 Custom<br/>
<input type="checkbox" name="default_options[custompro]"', @$context['member']['options']['custompro'] ? ' checked="checked"' : '', ' class="check" /> - Custom Pro</td>
    </tr>


and it seems to be doing the same thing  ???
The only thing php can't do is tell you how much milk is left in the fridge.



kegobeer

Have you cleared your cache?  When you view source, is the code correct?  Where did you put this code?

I'm no expert when it comes to custom fields, so I'm unsure where and how the custom fields get written to the database.  Can you post a link to this so I can see it?
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

1MileCrash

The source is right.

a followed the tutorial here:

http://www.unknownbrackets.com/tutorials/custom-profile

the link to my forum is: http://model98.org

they are stored in the themes table i think.
The only thing php can't do is tell you how much milk is left in the fridge.



kegobeer

Where are these checkboxes at?  I don't see any on your forum.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

1MileCrash

#6
in a users profile.

user and pass removed

go to your profile, then forum profile information. at the bottom,
Owned Tippmann 98 Models:    
- Model 98
- 98 Custom
- Custom Pro

checking any of the boxes, then saving, permanently checks them. you cant save them unchecked.
The only thing php can't do is tell you how much milk is left in the fridge.



kegobeer

Near as I can tell, if the checkbox is empty the code is just ignoring it.  Why that is, I don't know.  Since that tutorial was written quite a while ago, I guess something is different in the way the html form is being handled.  I'll have to poke around and try to figure out that code.

Go ahead and change the checkbox code and put the value="1" back.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

kegobeer

I still haven't gotten any further with this.  I've duplicated this problem on my RC2 test forum.  I wish I had a 1.0.6 forum to experiment with, but I don't.  Honestly, I don't know if this ever worked.

Custom fields are added to the database in the makeThemeChanges function, which is called from saveProfileChanges (both in Profile.php.)  If the checkbox is cleared, there simply is no value whatsoever in the $_POST['default_options'] variable.  That's why the boxes are permanently checked once you tick the box.

This is something for the devs to look at.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

JayBachatero

http://www.unknownbrackets.com/tutorials/custom-profile  review the way is done there it's using @$context['member']['options']['blah'] == 'blah' instead of @$context['member']['options']['blah'['blah']
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

kegobeer

Quote from: JayBachatero on February 17, 2006, 09:28:29 AM
http://www.unknownbrackets.com/tutorials/custom-profile  review the way is done there it's using @$context['member']['options']['blah'] == 'blah' instead of @$context['member']['options']['blah'['blah']

That's for a listbox.  The code Tipp is using is exactly like the checkbox code on the tutorial.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

jacortina

Try adding this (supplying the correct, matching field name in the brackets) right before each of the checkbox input entries:



<input type="hidden" name="default_options[.......]" value="0" />



(make sure to keep the 'value="1"' parameter in the originals).

kegobeer

Quote from: jacortina on April 15, 2006, 06:48:37 PM
Try adding this (supplying the correct, matching field name in the brackets) right before each of the checkbox input entries:



<input type="hidden" name="default_options[.......]" value="0" />



(make sure to keep the 'value="1"' parameter in the originals).


This has been solved in another thread; you must check for no value immediately before the data is written to the database.  However, I don't think you can have two form inputs with the same name, as one will always overwrite the other.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

jacortina

Quote from: kegobeer on April 15, 2006, 06:52:55 PM

This has been solved in another thread; you must check for no value immediately before the data is written to the database.  However, I don't think you can have two form inputs with the same name, as one will always overwrite the other.

Having the same name is a common practice. And in this case, the entire purpose is to have the value overwritten. The '0' (zero) value will be posted every time. When the box is checked, it will be overwritten with a value of '1'.

Unchecked boxes are 'unsuccessful' and are not supposed to be included in posted data. That's per the specification:

http://www.w3.org/TR/REC-html40/interact/forms.html#checkbox
Quotecheckboxes
Checkboxes (and radio buttons) are on/off switches that may be toggled by the user. A switch is "on" when the control element's checked attribute is set. When a form is submitted, only "on" checkbox controls can become successful.
Several checkboxes in a form may share the same control name. Thus, for example, checkboxes allow users to select several values for the same property. The INPUT element is used to create a checkbox control.

Note the language about having the same name. Note also that only 'on' checkboxes can be successful (that is, be submitted via POST).

1MileCrash

#14
..Another bump. I finally got around to trying to fix this.

And...it doesnt work right.


<input type="hidden" name="default_options[model98]" value="0" />
<input type="checkbox" name="default_options[model98]" value="1"', @$context['member']['options']['model98'] ? ' checked="checked"' : '', ' class="check" /> - Model 98<br/>
<input type="hidden" name="default_options[98custom]" value="0" />
<input type="checkbox" name="default_options[98custom]" value="1"', @$context['member']['options']['98custom'] ? ' checked="checked"' : '', ' class="check" /> - 98 Custom<br/>
   <input type="hidden" name="default_options[custompro]" value="0" />
<input type="checkbox" name="default_options[custompro]" value="1"', @$context['member']['options']['custompro'] ? ' checked="checked"' : '', ' class="check" /> - Custom Pro</td>


Now, i can uncheck them and it saves. But the result is the same (IE if i have one checked it looks like i have all three in display.template.). If i uncheck all three boxes, then it shows nothing in display.template (which is right), but if i check one, it displays all three (which is wrong)

Here is what is in display.template.
if (!$message['member']['options']['model98'] && !$message['member']['options']['98custom'] && !$message['member']['options']['custompro'])
{

} else {
echo'
<table style="margin-bottom: 3px;" width="100%" class="tborder" cellpadding="2" cellspacing="1"><tr><td width="100%" class="windowbg">

', !isset($message['member']['options']['model98']) ? '' : '<img src="http://www.model98.org/forum/Themes/m98forums2/model98owner.gif"/>', '
', !isset($message['member']['options']['98custom']) ? '' : '<img src="http://www.model98.org/forum/Themes/m98forums2/98customowner.gif"/>', '
', !isset($message['member']['options']['custompro']) ? '' : '<img src="http://www.model98.org/forum/Themes/m98forums2/customproowner.gif"/>', '
</td></tr></table>';
}
The only thing php can't do is tell you how much milk is left in the fridge.



Advertisement: