droidus Posted August 25, 2011 Share Posted August 25, 2011 i am having issues checking which value is checked in a form. here is my code for it: <input type="radio" name="accountActivation" id="no" value="no" checked=" <? if (isset($register_errors)) { if (($_POST['accountActivation']) == "no") { echo "checked"; } } ?> " /> when i first open the page, no is checked. why is this, when there should be no errors, and the radio should not even be checked in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/ Share on other sites More sharing options...
etnastyles Posted August 25, 2011 Share Posted August 25, 2011 In a radio button group 1 button is always checked maybe if you need a unchecked logic just use check boxes - they are about the same anyway... Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1261905 Share on other sites More sharing options...
dougjohnson Posted August 25, 2011 Share Posted August 25, 2011 All radio buttons can be "unchecked". With radio buttons I don't think you use checked=. You just use CHECKED. If there is no CHECKED in the input tag, the radio button will be unchecked. <input type="radio" name="accountActivation" id="no" value="no" <? if (isset($register_errors)) { if (($_POST['accountActivation']) == "no") { echo "checked"; } } ?> " /> Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1261908 Share on other sites More sharing options...
droidus Posted August 25, 2011 Author Share Posted August 25, 2011 great; thanks! Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1261917 Share on other sites More sharing options...
droidus Posted August 26, 2011 Author Share Posted August 26, 2011 now for the checkbox, what am i doing wrong?: <input type="checkbox" name="noIdentity" id="noIdentity" value="noIdentity" <?php if(isset($_POST['errors']) && isset($_POST[noIdentity])) { echo " checked='checked '"; } ?> /> Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1262125 Share on other sites More sharing options...
dougjohnson Posted August 26, 2011 Share Posted August 26, 2011 Set the checked attribute to yes or no. CHECKBOX="YES" Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1262323 Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2011 Share Posted August 26, 2011 You have a space in the value after the 'd' and before the single-quote in 'checked '". Use either - checked="checked" or checked='checked' Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1262324 Share on other sites More sharing options...
droidus Posted August 26, 2011 Author Share Posted August 26, 2011 i think that the problem is though, that the code doesn't even work. i check it, submit the form, and i come back to that field, and it is not checked. here is my updated code: <?php if(isset($_POST[errors]) && isset($_POST[noIdentity])) { echo 'checked=yes'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1262372 Share on other sites More sharing options...
Pikachu2000 Posted August 26, 2011 Share Posted August 26, 2011 Instead of posting a line or two of code, post all of the relevant code. Nobody can just guess what's going on without seeing it. Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1262407 Share on other sites More sharing options...
droidus Posted August 27, 2011 Author Share Posted August 27, 2011 if($sent != true) { echo" <div class='form'><form action='' method='post'> <p class='form'>User ID: <br /><input name='memberID' type='hidden' value='<?php echo $row[id]; ?>' /> Your User ID will be logged for identity purposes. <br /><input type='checkbox' name='noIdentity' id='noIdentity' value='noIdentity' <?php if(isset($_POST[errors]) && isset($_POST[noIdentity])) { echo 'checked=yes'; } ?> <label for='noIdentity'> Check here if you would rather send information anonymously.</label></p> <p class='form'><label for='otherEmail'>E-Mail (If the e-mail address is different from the one that you registered with, please enter it if you would like a response)<span style='color: red'>:</span></label><br /><input type='text' size='60' class='form' name='otherEmail' value='$_POST[otherEmail]' /></p> <p class='form'><label for='subject'>Subject:</label> <span style='font-weight: bolder; color: red;'>*</span><br /><input name='subject' type='text' class='form' id='subject' value='$_POST[subject]' size='60' /></p> <p class='form'><label for='message'>Message:</label> <span style='font-weight: bolder; color: red;'>*</span> <br /><textarea name='message' cols='42' rows='9' class='form' id='message' value='$_POST[message]'></textarea></p> <p class='form'><label for='phone'>Phone:</label> <br /><input name='phone' type='text' class='form' id='phone' value='$_POST[phone]' size='60' /></p> <p class='form'><label for='websote'>Website URL (list the URL of the site that you had issues with):</label> <br /><input name='website' type='text' class='form' id='website' value='$_POST[website]' size='60' /></p> <table><tr><td width='134'><p class='form' style='margin-top: 3px;'>AntiSpam Protection: <span style='font-weight: bolder; color: red;'>*</span> </td> <td width='120'><label for='antiSpam'>What is 7+3?</label></p></td><td><input type='text' name='antiSpam' class='captcha' size='6' maxlength='5' value='$_POST[antiSpam]'></td></tr></table> <div align='center'> <p> <div style='line-height:1.25em;'> <strong><img src='http://mysite.com/Images/lock_icn.gif' alt='' width='14' height='16' /> Privacy Notice</strong>: Content sent in this form will remain confidential and will not be sold to third parties. We respect your privacy and promise not to send you spam. We hate spam too! Do <strong>NOT</strong> send personal information, such as your social security number, through this form.</p> </div> <input type='submit' value='Send my Message!' class='formsubmit' name='submit' /> </form> <p>All fields marked with <span style='font-weight: bolder; color: red;'>*</span> are required.</p> <?php "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1262483 Share on other sites More sharing options...
Drummin Posted August 27, 2011 Share Posted August 27, 2011 I don't see the closing " />" on your noIdentity input tag Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1262531 Share on other sites More sharing options...
droidus Posted August 28, 2011 Author Share Posted August 28, 2011 so now its: <input type='checkbox' name='noIdentity' id='noIdentity' value='noIdentity' <?php if(isset($_POST[errors]) && isset($_POST[noIdentity])) { echo 'checked=yes'; } ?> /> still doesn't work though Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1262747 Share on other sites More sharing options...
droidus Posted August 30, 2011 Author Share Posted August 30, 2011 sorry, <?php if(isset($_POST[errors]) && isset($_POST[noIdentity])) { echo 'checked=checked'; } else {echo 'bad'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1263515 Share on other sites More sharing options...
PFMaBiSmAd Posted August 30, 2011 Share Posted August 30, 2011 Are you sure you only want to check the box is there are errors - isset($_POST[errors])? Have you checked the two $_POST values that your logic is testing so that you know they have values that would cause your code to do what you expect? Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1263523 Share on other sites More sharing options...
droidus Posted September 1, 2011 Author Share Posted September 1, 2011 Are you sure you only want to check the box is there are errors - isset($_POST[errors])? no, also, if they had already checked the box. here is the code that I'm testing on a separate page: <form id="form1" name="form1" method="post" action=""> <?php $errors=true; echo "<input type='checkbox' name='noIdentity' id='noIdentity' value='noIdentity'"; if(isset($errors) && isset($POST['noIdentity'])) { echo 'checked=checked'; } else {echo 'bad'; } echo "/>"; ?> <input type="submit" name="submit" id="submit" value="Submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1264129 Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2011 Share Posted September 1, 2011 no, also, if they had already checked the box. ^^^ That's not what your logic is doing. Your logic says if $_POST[errors] is set AND $_POST[noIdentity] is set, i.e. both of them must be set to produce a TRUE value. In the last code you posted, you have $POST['noIdentity']. It should be $_POST['noIdentity'] Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1264159 Share on other sites More sharing options...
droidus Posted September 1, 2011 Author Share Posted September 1, 2011 right - if errors is set, and they checked the checkbox, then 'checked=checked'. this does not change the value being submitted to the form. this is only so they do not have to recheck the box if they sent the form, and there are errors. Quote Link to comment https://forums.phpfreaks.com/topic/245691-echoing-checked-value/#findComment-1264533 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.