Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: Checkbox

  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    66
    Thanks
    8
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    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...

  • #3
    New Coder
    Join Date
    Nov 2005
    Posts
    66
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What are the possible values of $checked?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Nov 2005
    Posts
    66
    Thanks
    8
    Thanked 0 Times in 0 Posts
    i dont know?

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

  • #6
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    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">

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #8
    New Coder
    Join Date
    Nov 2005
    Posts
    66
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    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

  • #10
    New Coder
    Join Date
    Nov 2005
    Posts
    66
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Awesome, thanks!!!

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

  • #11
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    always glad to help a fellow coder...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •