Image checkbox

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by bunglebrown, Sep 27, 2008.

  1. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    Is it possible to substitute a checkbox for an image so that I can post user selections to myself? If so can anyone suggest how..?

    I've used
    Code:
    input type='image' value='Submit'
    to make an image a submit button so I am hoping I can do something similar with the checkbox.

    Indebted
     
  2. scopey

    scopey New Member

    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    0
    I don't really understand but if you are trying to substitute the normal, semi-ugly checkboxes for your own images, it's possible with a bit of javascript.

    Quickly written code below (untested):

    HTML:
    <script type="text/javascript">
    var chkboxTicked = new Image();
    chkboxTicked.src = "chkbox_ticked.png";
    var chkboxEmpty = new Image();
    chkboxEmpty.src = "chkbox_empty.png";
    function submitcheckboxes(){
    var checkboxes = document.getElementsByName("imgcheckboxes");
    for(var i in checkboxes){
    var location = document.getElementById("form1");
    var input = document.createElement('input');
    input.setAttribute('style','display:none;');
    input.setAttribute('type','hidden');
    input.setAttribute('name',checkboxes[i].title);
    if(checkboxes[i].src = "chkbox_ticked.png"){
    input.setAttribute('value',1);
    } else {
    input.setAttribute('value',0);
    }
    location.appendChild(input);
    }
    return true;
    }
    function toggleChkBox(that){
    if(that.src == chkboxEmpty.src){
    that.src = chkboxTicked.src;
    } else {
    that.src = chkboxEmpty.src;
    }
    }
    </script>
    <form id="form1" onsubmit="return submitcheckboxes()">
    <img name="imagecheckboxes" src="http://forums.x10hosting.com/programming-help/chkbox_empty.png" onclick="toggleChkBox(this)" title="checkbox1" />
    <img name="imagecheckboxes" src="http://forums.x10hosting.com/programming-help/chkbox_empty.png" onclick="toggleChkBox(this)" title="checkbox2" />
    </form>
    Just need to make two images called chkbox_empty.png and chkbox_ticked.png
     
    Last edited: Sep 27, 2008
  3. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    seems good and from there ... how do I get this information posted to me on the next page as I seem to be having a little trouble with the php coding that I have used on previous forms. It is below.

    PHP:
    <script language="php">
    $email $HTTP_POST_VARS[email];
    $mailto "my.email@myhost.com";
    $mailsubj "Title";
    $mailhead "From: $email\n";
    reset ($HTTP_POST_VARS);
    $mailbody "Data received:\n";
    while (list (
    $key$val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
    if (!
    eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto$mailsubj$mailbody$mailhead); }
    </script>
     
  4. scopey

    scopey New Member

    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    0
    $HTTP_POST_VARS is now deprecated... Use $_POST[] instead.

    To get whether the person ticked your checkbox or not, you just need to get $_POST['(Title of your checkbox img tag here)'] . The value should be 1 if it was ticked, and 0 if it was left empty. The code is probably buggy though... I will give it a test.

    [Edit]

    Wow, suprised I almost got my script perfect. The only mistakes I made was a couple of typos:

    HTML:
    <script type="text/javascript">
    var chkboxTicked = new Image();
    chkboxTicked.src = "chkbox_ticked.png";
    var chkboxEmpty = new Image();
    chkboxEmpty.src = "chkbox_empty.png";
    function submitcheckboxes(){
    var checkboxes = document.getElementsByName("imagecheckboxes");
    for(var i in checkboxes){
    var location = document.getElementById("form1");
    var input = document.createElement('input');
    input.setAttribute('style','display:none;');
    input.setAttribute('type','hidden');
    input.setAttribute('name',checkboxes[i].title);
    if(checkboxes[i].src == chkboxTicked.src){
    input.setAttribute('value',1);
    } else {
    input.setAttribute('value',0);
    }
    location.appendChild(input);
    }
    return true;
    }
    function toggleChkBox(that){
    if(that.src == chkboxEmpty.src){
    that.src = chkboxTicked.src;
    } else {
    that.src = chkboxEmpty.src;
    }
    }
    </script>
    <form id="form1" onsubmit="return submitcheckboxes()">
    <img name="imagecheckboxes" src="http://forums.x10hosting.com/programming-help/chkbox_empty.png" onclick="toggleChkBox(this)" title="checkbox1" />
    <img name="imagecheckboxes" src="http://forums.x10hosting.com/programming-help/chkbox_empty.png" onclick="toggleChkBox(this)" title="checkbox2" />
    </form>
     
    Last edited: Sep 29, 2008
  5. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    scopey this code looks good but I'm having a few problems with my php - I changed all the $HTTP_POST_VARS to $_POST[] but it doesn't want to work for me and I didn't know quite in what place to enter the $_POST[checkbox1].

    ...code looks awesome though/.
     
  6. scopey

    scopey New Member

    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    0
    Ok... This is the PHP page I was testing it with:

    HTML:
    <?php
    print_r($_POST);
    ?>
    
    <script type="text/javascript">
    var chkboxTicked = new Image();
    chkboxTicked.src = "test/chkbox_ticked.png";
    var chkboxEmpty = new Image();
    chkboxEmpty.src = "test/chkbox_empty.png";
    function submitcheckboxes(){
        var checkboxes = document.getElementsByName("imagecheckboxes");
        for(var i in checkboxes){
            var location = document.getElementById("form1");
            var input = document.createElement('input');
            input.setAttribute('style','display:none;');
            input.setAttribute('type','hidden');
            input.setAttribute('name',checkboxes[i].title);
            input.setAttribute('id',checkboxes[i].title);
            location.appendChild(input);
            if(checkboxes[i].src == chkboxTicked.src){
                document.getElementById(checkboxes[i].title).value = "1";
            } else {
                document.getElementById(checkboxes[i].title).value = "0";
            }
        }
        return true;
    }
    function toggleChkBox(that){
        if(that.src == chkboxEmpty.src){
            that.src = chkboxTicked.src;
        } else {
            that.src = chkboxEmpty.src;
        }
    }
    </script>
    <form id="form1" method="post" action="tester.php" onsubmit="return submitcheckboxes()">
    <img name="imagecheckboxes" src="test/chkbox_empty.png" onclick="toggleChkBox(this)" title="box1" />
    <img name="imagecheckboxes" src="test/chkbox_empty.png" onclick="toggleChkBox(this)" title="box2" />
    <input type="submit" name="submit" />
    </form>
    For me, that returned:

    Code:
    Array (     [submit] => Submit Query     [box1] => 0     [box2] => 1     [undefined] =>  ) 
    See the names of my image tickboxes are box1 and box2? That's how the tickboxes are submitted.

    So, if you put in php:

    PHP:
    <?
    if(
    $_POST['box1'] == 1){
    print 
    "Box 1 was ticked";
    }
    ?>
    It will write 'Box 1 was ticked' if box 1 was ticked.

    Similarly, you can just write the following for the same result:

    PHP:
    <?
    if(
    $_POST['box1']){
    print 
    "Box 1 was ticked";
    }
    ?>
     
  7. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    That's very useful scopey. . .thanks a lot. I just need to mail it to myself now and if possible remove the ones that haven't been checked. Also wanted to ask you if it was possible to make the images on the results page the same as they were as they were submitted on the previous but I don't want to ask too much of you so anything more you can add or not is great - you've really helped me already. .
    -------------------------------------------------------------------------------------------------------------------------
    Here is the php (below) that I have it working for but wanted to ask if it is possible to have only the images selected mailed to me. . . . without being too picky.

    PHP:
    <?php 

    // Create local PHP variables from the info the user gave in the Flash form -disabled message field 
    $box1   $_POST['box1']; 
    $box2   $_POST['box2']; 

    // Strip slashes on the Local variables -disabled message field 
    $box1  stripslashes($box1); 
    $box2      stripslashes($box2); 

        
    $from $fromEmail
        
    $subject "Spaces chosen"
        
    //Begin HTML Email Message 
        
    $message "<b>Box 1:</b><br>{$box1} <br><br> <b>Box 2:</b><br>$box2";
        
        echo 
    '
    '
    ;
       
    //end of message 
        
    $headers  "From: $from\r\n"
        
    $headers .= "Content-type: text/html\r\n"
        
    $to "reg.brooks@hotmail.com"

        
    mail($to$subject$message$headers); 
         
    exit(); 
    ?>
     
    Last edited: Sep 30, 2008
  8. Salvatos

    Salvatos Member Prime Account

    Messages:
    562
    Likes Received:
    1
    Trophy Points:
    18
    Sure that should be easy. I've not gone through your whole discussion but from what I remember correctly, the logic in my opinion would be this.

    After
    Code:
    $box1  = stripslashes($box1);
    $box2      = stripslashes($box2);
    Add
    Code:
    if ($box1 == "1") { // If the box is ticked
    $box1 = "<img src='test/chkbox_ticked.png'>";
    }
    else {
    $box1 = "<img src='test/chkbox_empty.png'>";
    }
    
    if ($box2 == "1") { // If the box is ticked
    $box2 = "<img src='test/chkbox_ticked.png'>";
    }
    else {
    $box2 = "<img src='test/chkbox_empty.png'>";
    }
    You should include the whole path of the image (starting with http://) for your browser to find it when you read it in your e-mail though. If I'm not mistaken, this should echo your boxes images instead of the number that represents their value.
     
  9. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    thanks Salvatos...

    this is a nice idea but doesn't seem to send the images as they were submitted..

    Also what I meant to say is that I want the images to be as they were on the next page and only the title of the selected images mailed to me (the mailing has been achieved). .

    Would be unreal if this worked though..
     
  10. Salvatos

    Salvatos Member Prime Account

    Messages:
    562
    Likes Received:
    1
    Trophy Points:
    18
    When you say "next page", do you mean that you want to replace this
    Code:
    if($_POST['box1'] == 1){
    print "Box 1 was ticked";
    }
    By the image?
     
  11. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    Yes in the results page to exactly mimic how the last page appeared when it was submitted. Yet to still have the email sending the data (not image) of the selections.
     
  12. Salvatos

    Salvatos Member Prime Account

    Messages:
    562
    Likes Received:
    1
    Trophy Points:
    18
    Edit: I'm not a pro so maybe you want to make a copy of your files before testing my suggestions ;)

    Okay, then... I don't like to give too much of my own advice on Scopey's code but I think you could use this and edit a bit if it doesn't seem to suit your case. Explanations to follow.

    Code:
    [COLOR=#000080]<?php[/COLOR]
    [COLOR=#000080]// Boxes empty by default[/COLOR]
    [COLOR=#000080][FONT=Courier New][COLOR=#007700]$img_box1 = [/COLOR][COLOR=#000000]"test/chkbox_empty.png";[/COLOR][/FONT][/COLOR]
    [FONT=Courier New][COLOR=#007700]$img_box2 = [/COLOR][COLOR=#000000]"test/chkbox_empty.png";[/COLOR][/FONT]
     
    // Tick boxes if user has ticked them
    [COLOR=#000080][FONT=Courier New][COLOR=#007700]if([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'box1'[/COLOR][COLOR=#007700]] == [/COLOR][COLOR=#0000bb]1[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]){[/COLOR][/FONT]
    [COLOR=#007700][FONT=Courier New]$img_box1 = [COLOR=#000000]"test/chkbox_ticked.png";[/COLOR][/FONT]
    [FONT=Courier New]}[/FONT]
     
    [/COLOR][/COLOR][COLOR=#000080][COLOR=#007700][COLOR=#007700][FONT=Courier New][COLOR=#007700]if([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'box2'[/COLOR][COLOR=#007700]] == [/COLOR][COLOR=#0000bb]1[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]){[/FONT][/COLOR]
    [COLOR=#007700][FONT=Courier New]$img_box2 = [COLOR=#000000]"test/chkbox_ticked.png";[/COLOR][/FONT]
    [FONT=Courier New]}[/FONT]
    [/COLOR][/COLOR][/COLOR]?>[/COLOR]
     
    [COLOR=#800000]<script type=[COLOR=#0000ff]"text/javascript"[/COLOR]>[/COLOR]
    var chkboxTicked = new Image();
    chkboxTicked.src = "test/chkbox_ticked.png";
    var chkboxEmpty = new Image();
    chkboxEmpty.src = "test/chkbox_empty.png";
    function submitcheckboxes(){
        var checkboxes = document.getElementsByName("imagecheckboxes");
        for(var i in checkboxes){
            var location = document.getElementById("form1");
            var input = document.createElement('input');
            input.setAttribute('style','display:none;');
            input.setAttribute('type','hidden');
            input.setAttribute('name',checkboxes[i].title);
            input.setAttribute('id',checkboxes[i].title);
            location.appendChild(input);
            if(checkboxes[i].src == chkboxTicked.src){
                document.getElementById(checkboxes[i].title).value = "1";
            } else {
                document.getElementById(checkboxes[i].title).value = "0";
            }
        }
        return true;
    }
    function toggleChkBox(that){
        if(that.src == chkboxEmpty.src){
            that.src = chkboxTicked.src;
        } else {
            that.src = chkboxEmpty.src;
        }
    }
    [COLOR=#800000]</script>[/COLOR]
    [COLOR=#ff8000]<form id=[COLOR=#0000ff]"form1"[/COLOR] method=[COLOR=#0000ff]"post"[/COLOR] action=[COLOR=#0000ff]"tester.php"[/COLOR] onsubmit=[COLOR=#0000ff]"return submitcheckboxes()"[/COLOR]>[/COLOR]
    [COLOR=#800080]<img name=[COLOR=#0000ff]"imagecheckboxes"[/COLOR] src=[COLOR=#0000ff]"<? echo "$img_box1"; ?>"[/COLOR] onclick=[COLOR=#0000ff]"toggleChkBox(this)"[/COLOR] title=[COLOR=#0000ff]"box1"[/COLOR] />[/COLOR]
    [COLOR=#800080]<img name=[COLOR=#0000ff]"imagecheckboxes"[/COLOR] src=[COLOR=#0000ff]"<? echo "$img_box2"; ?>"[/COLOR] onclick=[COLOR=#0000ff]"toggleChkBox(this)"[/COLOR] title=[COLOR=#0000ff]"box2"[/COLOR] />[/COLOR]
    [COLOR=#ff8000]<input type=[COLOR=#0000ff]"submit"[/COLOR] name=[COLOR=#0000ff]"submit"[/COLOR] />[/COLOR]
    [COLOR=#ff8000]</form>[/COLOR]
    So this code assumes that you are on tester.php when you fill the form and that you send it to the same page. At first you set the path of the images to empty, by default, so if the user is coming to the page for the first time the boxes will be empty.
    Then, if the form has been sent and a box ticked, its image path will be changed accordingly.
    You then have the JavaScript that I didn't change and finally the form is displayed, with its images depending on if it has been sent already or not (again, they will be empty by default).

    Now I'm not really sure about how you're working on this. I don't know if you have all this in one page or two. If it's on one page, you can just do this to include your e-mail sending function, probably at the very beginning:

    Code:
    if (isset($_POST['box1']) && $_POST['box1'] != "" && isset($_POST['box2']) && $_POST['box2'] != "") {
    // insert your e-mail code here
    }
    If, on the other hand, you have it on two pages (for example test.php sending to tester.php), it shouldn't be too hard to do either. You can just leave the first page as it was and change the second to what I have posted above (including your e-mail code).

    I don't know if I made myself clear and I can't test it, so it might well not work and I apologize in advance. If, maybe, you can send me the up to date content of the concerned page(s) I could be a little more certain about what I'm telling you ;)

    Hope it works, and hope that helps :)
     
    Last edited: Sep 30, 2008
  13. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    great - I have the images staying as they were on the results page (yes there are 2 pages involved here).. which is awesome. . I had to change this

    Code:
    <img name="imagecheckboxes" src="<? echo "$img_box1"; ?>" onclick="toggleChkBox(this)" title="box1" />
    <img name="imagecheckboxes" src="<? echo "$img_box2"; ?>" onclick="toggleChkBox(this)" title="box2" />
    to

    Code:
    <img name="imagecheckboxes" src="test/chkbox_empty.png" onclick="toggleChkBox(this)" title="box1" />
    <img name="imagecheckboxes" src="test/chkbox_empty.png" onclick="toggleChkBox(this)" title="box1" />
    as it wasn't recognising the src. But this works as I said and nicely. . however when I add the email part everything stops - below I have put what I am using and perhaps there will be something obviously apparent in there.. thanks for staying with me..

    PHP:
    <?php
    if (isset($_POST['box1']) && $_POST['box1'] != "" && isset($_POST['box2']) && $_POST['box2'] != "") {
    // insert your e-mail code here

    // Strip slashes on the Local variables -disabled message field 
    $box1  stripslashes($box1); 
    $box2      stripslashes($box2);

        
    $from $fromEmail
        
    $subject "Spaces chosen"
        
    //Begin HTML Email Message 
        
    $message "<b>Box 1:</b><br>{$box1} <br><br> <b>Box 2:</b><br>$box2";
        
        echo 
    '
    '
    ;
       
    //end of message 
        
    $headers  "From: $from\r\n"
        
    $headers .= "Content-type: text/html\r\n"
        
    $to "my.email@myhost.com"

        
    mail($to$subject$message$headers); 
         
    exit(); 
    }

    // Boxes empty by default
    $img_box1 "test/chkbox_empty.png";
    $img_box2 "test/chkbox_empty.png";
     
    // Tick boxes if user has ticked them
    if($_POST['box1'] == 1){
    $img_box1 "test/chkbox_ticked.png";
    }
     
    if(
    $_POST['box2'] == 1){
    $img_box2 "test/chkbox_ticked.png";
    }
    ?>
     
  14. Salvatos

    Salvatos Member Prime Account

    Messages:
    562
    Likes Received:
    1
    Trophy Points:
    18
    Yes I think I can see the problem. Here is the fix:

    Code:
    [COLOR=#000000][FONT=Courier New][COLOR=#0000bb]<?php [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#007700]if (isset([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'box1'[/COLOR][COLOR=#007700]]) && [/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'box1'[/COLOR][COLOR=#007700]] != [/COLOR][COLOR=#dd0000]"" [/COLOR][COLOR=#007700]&& isset([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'box2'[/COLOR][COLOR=#007700]]) && [/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'box2'[/COLOR][COLOR=#007700]] != [/COLOR][COLOR=#dd0000]"") [/COLOR][/FONT][COLOR=#007700][FONT=Courier New]{ [/FONT][/COLOR]
     
    [FONT=Courier New][COLOR=#ff8000]// Strip slashes on the Local variables -disabled message field  [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$box1  [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]stripslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'box1'[/COLOR][COLOR=#007700]][/COLOR][/COLOR][/FONT][FONT=Courier New][COLOR=#007700]);  [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$box2  [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]stripslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'box2'[/COLOR][COLOR=#007700]][/COLOR][/COLOR][/FONT][FONT=Courier New][COLOR=#007700]); [/COLOR][/FONT]
     
    [FONT=Courier New][COLOR=#0000bb]$from [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]$fromEmail[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];  [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$subject [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"Spaces chosen"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New];  [/FONT][/COLOR]
    [FONT=Courier New][COLOR=#ff8000]//Begin HTML Email Message  [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$message [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"<b>Box 1:</b><br>{$box1} <br><br> <b>Box 2:</b><br>$box2"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]; [/FONT][/COLOR]
     
    [FONT=Courier New][COLOR=#007700]echo [/COLOR][/FONT][COLOR=#dd0000][FONT=Courier New]' [/FONT][/COLOR][FONT=Courier New][COLOR=#dd0000]'[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]; [/FONT][/COLOR]
    [FONT=Courier New][COLOR=#ff8000]//end of message  [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$headers  [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"From: $from\r\n"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];  [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$headers [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"Content-type: text/html\r\n"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];  [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$to [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"my.email@myhost.com"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];  [/COLOR][/FONT]
     
    [FONT=Courier New][COLOR=#0000bb]mail[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$to[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$subject[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$message[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$headers[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]);[/FONT][/COLOR]
     
     
    [FONT=Courier New][COLOR=#ff8000]// Boxes empty by default [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$img_box1 [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"test/chkbox_empty.png"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]; [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$img_box2 [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"test/chkbox_empty.png"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]; [/FONT][/COLOR]
     
    [FONT=Courier New][COLOR=#ff8000]// Tick boxes if user has ticked them [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#007700]if([/COLOR][COLOR=#0000bb]$box1[/COLOR][COLOR=#007700] == "[/COLOR][COLOR=#0000bb]1"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]){ [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$img_box1 [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"test/chkbox_ticked.png"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]; [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#007700]} [/COLOR][/FONT]
     
    [FONT=Courier New][COLOR=#007700]if([/COLOR][COLOR=#0000bb]$box2[/COLOR][COLOR=#007700] == "[/COLOR][COLOR=#0000bb]1"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]){ [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]$img_box2 [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"test/chkbox_ticked.png"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]; [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#007700]}[/COLOR][/FONT]
     
    [FONT=Courier New][COLOR=#007700]exit();  [/COLOR][/FONT]
    [FONT=Courier New][COLOR=#007700]}[/COLOR][/FONT]
    [FONT=Courier New][COLOR=#0000bb]?>[/COLOR][/FONT][/COLOR]
    Your e-mail probably couldn't work because it was looking for unidentified variables ($box1 and $box2). I also moved your "exit()" to the end of the code so it now includes all of it and changed the conditions for the variables. Hopefully it should fix the other issue, since...

    This is not good in my opinion:
    Code:
    <img name="imagecheckboxes" src="test/chkbox_empty.png" onclick="toggleChkBox(this)" title="box1" />
    <img name="imagecheckboxes" src="test/chkbox_empty.png" onclick="toggleChkBox(this)" title="box1" />
    First, they are both titled "box1". But if you leave it like this it should always show as empty. Do you really get them ticked when they should be?
     
  15. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    Yeh thanks - that 'box 1' confusion was a typo. But to clear up below is what I used on the results page. The couple of lines I changed were on the previous page and all is now working so a massive thanks to those involved. Last request is just to get the ticked boxes mailed to me - I'm not interested in the others and don't want to have to scan hundreds of boxes each time. . . it's not vital of course but always good to learn. . . regards

    PHP:
    <?php
    // Boxes empty by default
    $img_box1 "test/chkbox_empty.png";
    $img_box2 "test/chkbox_empty.png";
     
    // Tick boxes if user has ticked them
    if($_POST['box1'] == 1){
    $img_box1 "test/chkbox_ticked.png";
    }
     
    if(
    $_POST['box2'] == 1){
    $img_box2 "test/chkbox_ticked.png";
    }
    ?>
     
    <form id="form1" method="post" action="tester.php" onsubmit="return submitcheckboxes()">
    <img name="imagecheckboxes" src="<? echo "$img_box1"; ?>" onclick="toggleChkBox(this)" title="box1" />
    <img name="imagecheckboxes" src="<? echo "$img_box2"; ?>" onclick="toggleChkBox(this)" title="box2" />
    <input type="submit" name="submit" />
    </form>

    <?php  

    // Create local PHP variables from the info the user gave in the Flash form -disabled message field  
    $box1   $_POST['box1'];  
    $box2   $_POST['box2'];  

    // Strip slashes on the Local variables -disabled message field  
    $box1  stripslashes($box1);  
    $box2      stripslashes($box2);  

        
    $from $fromEmail;  
        
    $subject "Title";  
        
    //Begin HTML Email Message  
        
    $message "<b>Box 1:</b><br>{$box1} <br><br> <b>Box 2:</b><br>$box2"
         
        echo 

    '

       
    //end of message  
        
    $headers  "From: $from\r\n";  
        
    $headers .= "Content-type: text/html\r\n";  
        
    $to "my.email@myhost.com";  

        
    mail($to$subject$message$headers);  
          
    exit();  
    ?>
     
  16. Salvatos

    Salvatos Member Prime Account

    Messages:
    562
    Likes Received:
    1
    Trophy Points:
    18
    You mean that you want the e-mail sent only when at least one box is ticked? Or you want the e-mail sent everytime but just showing the boxes if they are ticked?
    I'm really unsure about what you want exactly, so please give me a few examples of the exact behaviors you're looking for and I'll gladly do it for you. It's probably just a matter of placing a few conditions throughout the e-mail part of the code.
     
  17. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    So if a box isn't checked it doesn't say e.g. "box 7: not ticked" but just doesn't mention it . .

    For example if the email message reads:

    then I know that they are the boxes that have been checked rather than having to sift through the message to determine which have been checked (as there are rather a lot of 'boxes'). So to clarify - I wish to omit the unchecked boxes from the email message.

    I think that you are right and it is simply a question of conditions within the email code. . regards
     
  18. Salvatos

    Salvatos Member Prime Account

    Messages:
    562
    Likes Received:
    1
    Trophy Points:
    18
    I'm gonna post only the end of the code since it's the part concerned. Should be as simple as this:

    Code:
    [COLOR=#0000bb][FONT=Verdana][COLOR=#000000]<?php[/COLOR][/FONT][/COLOR]
    [COLOR=#0000bb][FONT=Verdana][COLOR=#000000]// Create local PHP variables from the info the user gave in the Flash form -disabled message field
    $box1 = $_POST['box1'];
    $box2 = $_POST['box2'];[/COLOR][/FONT][/COLOR]
     
    [COLOR=#0000bb][FONT=Verdana][COLOR=#000000]// Strip slashes on the Local variables -disabled message field
    $box1 = stripslashes($box1);
    $box2 = stripslashes($box2);[/COLOR][/FONT][/COLOR]
    [COLOR=#0000bb][FONT=Verdana][COLOR=#000000]$from = $fromEmail;
    $subject = "Title";
    //Begin HTML Email Message
    if ($box1 =="1") {
     if ($box2 =="1") {
      $message = "<b>Box 1:</b><br>{$box1} <br><br> <b>Box 2:</b><br>$box2";
     }
     else {
      $message = "<b>Box 1:</b><br>{$box1}";
     }
    }
    elseif ($box2 =="1") {
     $message = "<b>Box 2:</b><br>$box2";
    }
    else { // You can remove this else clause if you wish
     $message = "No box ticked in this form.";
    }[/COLOR][/FONT][/COLOR]
     
    [COLOR=#0000bb][FONT=Verdana][COLOR=#000000]echo '  ';
    //end of message
    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    $to = "[EMAIL="my.email@myhost.com"][COLOR=#0000ff]my.email@myhost.com[/COLOR][/EMAIL]";[/COLOR][/FONT][/COLOR]
     
    [COLOR=#0000bb][FONT=Verdana][COLOR=#000000]mail($to, $subject, $message, $headers);[/COLOR][/FONT][/COLOR]
     
    [COLOR=#0000bb][FONT=Verdana][COLOR=#000000]exit();
    ?>[/COLOR][/FONT][/COLOR]


    Edit: Somehow the CODE tag hates me and **cks up my indentation, so sorry for that.
     
    Last edited: Oct 3, 2008
  19. bunglebrown

    bunglebrown New Member

    Messages:
    157
    Likes Received:
    0
    Trophy Points:
    0
    Nice...

    Just thinking that the conditionals might not be practical as I have almost 200 images/checkboxes. Any other method we can apply for the same effect?

    thanks majorly ..

    Oh also I wanted to ask how to make it so that if no image/checkbox is submitted on the initial page then the use cannot pass to the next page. . sorry to ask more. . .
     
    Last edited: Oct 4, 2008
  20. Salvatos

    Salvatos Member Prime Account

    Messages:
    562
    Likes Received:
    1
    Trophy Points:
    18
    Hm depends, what is the problem you get with this one and want to avoid?
     

Share This Page