Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-28-2007, 04:22 AM   PM User | #1
Xibe
New Coder

 
Join Date: Nov 2005
Posts: 66
Thanks: 8
Thanked 0 Times in 0 Posts
Xibe is an unknown quantity at this point
Checkbox

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 Code:
<?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 Code:
<?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.
Xibe is offline   Reply With Quote
Old 07-28-2007, 04:28 AM   PM User | #2
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
PHP Code:
<?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...
matak is offline   Reply With Quote
Old 07-28-2007, 05:01 AM   PM User | #3
Xibe
New Coder

 
Join Date: Nov 2005
Posts: 66
Thanks: 8
Thanked 0 Times in 0 Posts
Xibe is an unknown quantity at this point
I gave the mqradio.php up there:
PHP Code:
<?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.

Last edited by Xibe; 07-28-2007 at 05:03 AM..
Xibe is offline   Reply With Quote
Old 07-28-2007, 05:12 AM   PM User | #4
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,292
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
What are the possible values of $checked?
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 07-28-2007, 05:20 AM   PM User | #5
Xibe
New Coder

 
Join Date: Nov 2005
Posts: 66
Thanks: 8
Thanked 0 Times in 0 Posts
Xibe is an unknown quantity at this point
i dont know?

I want them to be ON/OFF but I dont know how to make it that way.
Xibe is offline   Reply With Quote
Old 07-28-2007, 05:32 AM   PM User | #6
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
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">
matak is offline   Reply With Quote
Old 07-28-2007, 05:34 AM   PM User | #7
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,292
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Then what are you posting?
PHP Code:
$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?
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 07-28-2007, 05:38 AM   PM User | #8
Xibe
New Coder

 
Join Date: Nov 2005
Posts: 66
Thanks: 8
Thanked 0 Times in 0 Posts
Xibe is an unknown quantity at this point
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.
Xibe is offline   Reply With Quote
Old 07-28-2007, 05:48 AM   PM User | #9
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
Quote:
Originally Posted by Xibe View Post
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 Code:
<?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
matak is offline   Reply With Quote
Old 07-28-2007, 06:04 AM   PM User | #10
Xibe
New Coder

 
Join Date: Nov 2005
Posts: 66
Thanks: 8
Thanked 0 Times in 0 Posts
Xibe is an unknown quantity at this point
Awesome, thanks!!!

From that, I could work it out. I just needed the if(empty tidbit.
Xibe is offline   Reply With Quote
Old 07-28-2007, 06:07 AM   PM User | #11
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
always glad to help a fellow coder...
matak is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:24 AM.


Advertisement
Log in to turn off these ads.