Jump to content

[SOLVED] if checkbox is checked, echo '.... (???)


Moocat

Recommended Posts

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!

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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"; }?>

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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".

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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>';
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.