...

View Full Version : Checkbox



Xibe
07-28-2007, 05:22 AM
I'm trying to add an option to my admin panel that will allow the admin to set an option by checkbox.

mqcheck.php (page that will be added to admin area):

<?php
include 'mqradio.php';
echo ('
<head>
<style type="text/css">
.style1 {
font-family: Verdana;
}
.style2 {
font-size: xx-small;
}
.style3 {
font-size: x-small;
}
</style>
</head>

<form method="post" action="mqradio.php">
<input type="checkbox" name="rmq" style="height: 20px" checked="checked"></span>Radio Marquee</span></span><br>
<input name="Submit1" type="submit" value="submit"></form>
<span class="style1"><span class="style2">&nbsp;<br>
</span></span>')
?>

mqradio.php

<?php
$checked = $_POST['mrq'];
?>


I have two problems:
1.) This doesnt seem to work, because when I test it out, it wont set the value of the variable to either "on" (checked) or "off" (un-checked).

2.) After I've submitted the form it redirects me to a blank page (mqradio.php). I would like it to redirect me back to mqcheck.php, but if I add a redirect to mqradio, it screws up, because mqradio is included in mqcheck in the first place.


PLEASE HELP.

matak
07-28-2007, 05:28 AM
<?php
include 'mqradio.php';

$checked = $_POST['mrq'];

echo ('
<form method="post" action="mqradio.php">
<input type="checkbox" name="rmq" style="height: 20px" checked="'.$checked.'"></span>Radio Marquee</span></span><br>
<input name="Submit1" type="submit" value="submit"></form>
<span class="style1"><span class="style2">&nbsp;<br>
</span></span>');
?>


Try that, but there is still more information you need to give us so we could solve the problem. Post your mqradio.php code that communicates with the form...

Xibe
07-28-2007, 06:01 AM
I gave the mqradio.php up there:

<?php
$checked = $_POST['mrq'];
?>

let me try that... one sec.

Edit: Changing my mqcheck.php to what you said did nothing. Still the same problem.

_Aerospace_Eng_
07-28-2007, 06:12 AM
What are the possible values of $checked?

Xibe
07-28-2007, 06:20 AM
i dont know?

I want them to be ON/OFF but I dont know how to make it that way.

matak
07-28-2007, 06:32 AM
Well if you want a checked checkbox just add checked before closing tag

eg.
<input type="checkbox" name="rmq" style="height: 20px" checked>

else
<input type="checkbox" name="rmq" style="height: 20px">

_Aerospace_Eng_
07-28-2007, 06:34 AM
Then what are you posting?

$checked = $_POST['mrq'];
You have that but you don't know what you are posting to it? Are you posting a 0 or 1, yes or no?

Xibe
07-28-2007, 06:38 AM
If the admin checks the box, then I want $checked to be equal to 1 and if it is left unchecked, then $checked should be a 0.

How do I do this!!!? Im soo confused.

matak
07-28-2007, 06:48 AM
If the admin checks the box, then I want $checked to be equal to 1 and if it is left unchecked, then $checked should be a 0.

How do I do this!!!? Im soo confused.


<?php
echo ('
<head>
<style type="text/css">
.style1 {
font-family: Verdana;
}
.style2 {
font-size: xx-small;
}
.style3 {
font-size: x-small;
}
</style>
</head>

<form method="post" action="">
<input type="checkbox" name="rmq" style="height: 20px" >
<input name="Submit1" type="submit" value="submit"></form>');

if (empty($_POST['rmq'])){
echo "off"; #if not selected off
}
else {
echo $_POST['rmq']; #if selected will echo on
}

?>

Don't be confused

Xibe
07-28-2007, 07:04 AM
Awesome, thanks!!!

From that, I could work it out. I just needed the if(empty tidbit.

matak
07-28-2007, 07:07 AM
always glad to help a fellow coder...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum