box checked by default

Discussion in 'PHP' started by login, Oct 8, 2007.

  1. #1
    I want a news letter subscribe box checked by default. Is there anywhere in the form code below I can change something to get the box checked by default?

    Here is the form code:
    <input type="checkbox" name="subscribed" class="textbox" value="1" <?php if(isset($_REQUEST["subscribed"])){echo "checked";}?> />
     
    login, Oct 8, 2007 IP
  2. chicagoweb

    chicagoweb Peon

    Messages:
    30
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Add another variable to a form that will tell you if the form was submitted (ie. <form type="hidden" name="submitted" value="1">. In your original code change the if statement to read:
    if(!isset($_REQUEST['submitted']) || isset($_REQUEST["subscribed"])) {echo "checked";}
     
    chicagoweb, Oct 8, 2007 IP
    login likes this.
  3. login

    login Notable Member

    Messages:
    8,849
    Likes Received:
    349
    Best Answers:
    0
    Trophy Points:
    280
    #3
    Great, so the code that works and I use now is:

    <input type="checkbox" form type="hidden" name="subscribed" class="textbox" value="1" <?php if(!isset($_REQUEST['submitted']) || isset($_REQUEST["subscribed"])) {echo "checked";}?> />

    Green to you.

    chicagoweb, you are an expert, could you please take a look at this:
    http://forums.digitalpoint.com/showthread.php?t=500979

    I need the keywords in the h1 tag to show up in the title tag, how can I do that?
     
    login, Oct 8, 2007 IP
  4. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if you want it be standards compliant make that checked a checked="checked".
     
    tamen, Oct 8, 2007 IP
  5. login

    login Notable Member

    Messages:
    8,849
    Likes Received:
    349
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Thanks tamen, could you please take the time to incorporate that in the code for me, show me how the complete line would look. I dont understand really what you mean. I dont know php at all actually.
     
    login, Oct 8, 2007 IP
  6. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #6
    <input type="checkbox" form type="hidden" name="subscribed" class="textbox" value="1" <?php if(!isset($_REQUEST['submitted']) || isset($_REQUEST["subscribed"])) {echo 'checked="checked"';}?> />
     
    crazyryan, Oct 8, 2007 IP
  7. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Exactly crazyryan :)
     
    tamen, Oct 8, 2007 IP