Moocat Posted October 19, 2007 Share Posted October 19, 2007 i did a lot of research on this problem, and haven't yet been able to find a suitable solution. In fact, none of the solutions I've found so far work. Basically, I have a form with several textboxes, checkboxes, dropdowns, etc. If you want me to post the full file, I will. Basically, this form takes a bunch of information from a registered user on my forums (SMF ftw!), and posts it to a new thread in a board specified by the config code block. Now, my main problem is that when there are checkboxes, the output for $_POST['nameofchkbox'] will return either 'on' or NULL. here is the code for one of the checkboxes: echo' <TABLE align="center" width="100%" cols="3" border="0"> <TR align="center"> <TD class="appltext" colspan="5"><INPUT id="karakey" name="karakey" type="checkbox" />Karazhan Key</TD> </TR> </TABLE>'; and here is the function I want to use to display an image if the value is on, and a different image if the value is NULL (or that is what I'm trying to do): function displayCheck() { if (isset($_POST['cotkey'])) { echo 'something'; } } basically, once i get "something" to show up, I'll change that to html code to display an image. I didn't want to deal with the fact that I haven't even found an acceptable image yet. I also didn't want to put a parameter in the function yet, I just want to confirm that the code inside the function works properly first. I eventually want to be able to call the function with the checkbox's name as the parameter. here's the code that is calling the function: echo' <td><STRONG>CoT Key:</STRONG></td><td> ' . displayCheck() . '</td>'; and the function never outputs ANYTHING. I've tried changing the function around, e.g. if ($_POST['cotkey'] == 'on') { echo 'blah'; } and thus far nothing has given me any output. Anyone have any ideas here? I'm sure it's something simple and stupid that I'm missing. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/ Share on other sites More sharing options...
darkfreaks Posted October 19, 2007 Share Posted October 19, 2007 <?php if ($_POST['cotkey'] == "on") { echo "blah"; }?> <?php echo"<td><STRONG>CoT Key:</STRONG></td><td> " . displayCheck() . "</td>";?> Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373255 Share on other sites More sharing options...
Moocat Posted October 19, 2007 Author Share Posted October 19, 2007 thanks darkfreaks, but like i said, i did try that already, but am trying it again. tested that code... didn't give me any output when teh box was checked! any other ideas? also, what tags are you using? i tried [code][ /code] and [code=php:0] [/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373276 Share on other sites More sharing options...
Moocat Posted October 19, 2007 Author Share Posted October 19, 2007 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373358 Share on other sites More sharing options...
GingerRobot Posted October 19, 2007 Share Posted October 19, 2007 It seems to me that the problem must lie elsewhere. The method darkfreaks showed is the way to do it. Perhaps there it is something silly like a typo thats causing you problems. If possible try posting all the code. And yes, the tags you need are the tags(without the spaces) Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373365 Share on other sites More sharing options...
sasa Posted October 19, 2007 Share Posted October 19, 2007 are you use method="POST" in your form? name of checkbox is karakey and you check cotkey, is it OK? Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373366 Share on other sites More sharing options...
Moocat Posted October 19, 2007 Author Share Posted October 19, 2007 sorry, i posted the code for the wrong checkbox. here i'll put up the entire file for you guys as an attachment. it's rather long! also, tried the {code}{/code} tags and it didn't give me the pretty text coloring. wierd. {php} tags did though. but no "code" box. if i have some typo, i'll be angry lol. that's so typical for me... huge problem resulting from a tiny mistake! I'd really appreciate if someone could check over my work (not completely my work, it's based off a script someone else started), i would greatly appreciate it! hoping to get this whole thing done up as soon as possible PS: if you didn't guess or have previous knowledge of the game, it's a form for applying to a world of warcraft guild. I have it working great, except that it outputs "on" for those checkboxes. ALSO: very sorry for the giant one-line table. It has to be like that or SMF will space the table out like crazy. It automatically creates line breaks when it parses html also, i have all the checkboxes except one (the one i'm using for testing) the way i want them to work (displayCheck('nameofchkbox')). just ignore those. they intentionally don't work right now. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373394 Share on other sites More sharing options...
darkfreaks Posted October 19, 2007 Share Posted October 19, 2007 i see it doesnt work because the function only checks for cotkey and none of the other inputs like karakey <?php if ($_POST['cotkey'] == "on"|$_POST['karakey'] == "on"| $_POST['auchkey'] == "on"|$_POST['auchkey'] == "on"| $_POST['coilkey'] == "on"|$_POST['tkey'] == "on"| $_POST['thrallkey'] == "on") { echo "Blah"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373423 Share on other sites More sharing options...
Moocat Posted October 19, 2007 Author Share Posted October 19, 2007 it's only like that right now to test the one checkmark. I eventually want the function to take the name of the checkbox as a parameter, and then test that checkbox for checkedness. the problem right now is that it doesn't even work for the "cotkey" checkbox, and that's the only one that is being tested! here's an example of what the output will look like. the only thing i want to change is to make it so that it displays a "checkmark" image instead of saying "on" and an "X" image when it's null. sorry the image is so big. i'm not quite used to using GIMP yet. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373440 Share on other sites More sharing options...
darkfreaks Posted October 19, 2007 Share Posted October 19, 2007 try the function it should test for all inputs and just not kotkey right if it equals on it is going ot display a checkmark because that is the on value. so if it is on then you would have it echo "on" instead of bla. Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373442 Share on other sites More sharing options...
Moocat Posted October 19, 2007 Author Share Posted October 19, 2007 the code you gave me three posts up also didn't work. I'll see if i can explain this a little more accurately, as I still don't think you understand what I'm looking for. ok so we have a function. <?php function displayCheck($chkbox) { if ($_POST[$chkbox] == 'on') { echo '<img src="./checkon.jpg"></img>'; } else { echo '<img src="./checkoff.jpg"></img>'; } ?> so in the initial form we have the code for a single checkbox (pretending there's only one for now) <?php echo' <FORM action="../forum/index.php?page=' . $this_article_id . '" method="post"> <INPUT id="karakey" name="karakey" type="checkbox" /> </FORM>'; ?> then the info taken from the form is posted inside a new forum thread like this. <?php displayCheck('karakey') ?> the way it is currently displayed is <?php $_POST['karakey'] ?> and that simply outputs "on" which is NOT what I am looking for. I hope this clarifies what I'm looking for right now. I have the <?php echo 'blah'; ?> Simply as a placeholder/test. If it prints "blah" then i know i have the basic functionality down and can go back in and add the image tags instead of "blah". Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373476 Share on other sites More sharing options...
sasa Posted October 19, 2007 Share Posted October 19, 2007 in function change echo to return Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373495 Share on other sites More sharing options...
Moocat Posted October 19, 2007 Author Share Posted October 19, 2007 THANK YOU! that tiny little thing was exactly what i had wrong. Much thanks to everyone who helped, I should have a good grasp on getting this working now!!! I have some non-php work to do for a bit, but once that's done I'll adjust the function to suit my needs and mark this topic solved! Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373500 Share on other sites More sharing options...
darkfreaks Posted October 19, 2007 Share Posted October 19, 2007 your welcome moo and i cant believe i missed that Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373501 Share on other sites More sharing options...
Moocat Posted October 19, 2007 Author Share Posted October 19, 2007 neither can I... I'm a bit of a php newb, but hell, with all my experience in other languages i should have figured that out too it's always the little things causing the big problems! Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373505 Share on other sites More sharing options...
darkfreaks Posted October 19, 2007 Share Posted October 19, 2007 click solved plz ??? Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373508 Share on other sites More sharing options...
Moocat Posted October 19, 2007 Author Share Posted October 19, 2007 thanks again, everyone! topic solved! EDIT: yeah i was just waiting to make sure i didn't have any other problems, and also to finish the function so i could post what i ended up with: <?php function displayCheck($chkbx) { if ($_POST[$chkbx] == "on") { return '<img src="./tp-images/Image/checkon.gif"></img>'; } else { return '<img src="./tp-images/Image/checkoff.gif"></img>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73963-solved-if-checkbox-is-checked-echo/#findComment-373531 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.