x10Hosting Forums

Corporate Free Hosting for the Masses.



Register

Reply
 
LinkBack Thread Tools Display Modes
x10 Sophmore

Join Date: Aug 2008
Posts: 143
Credits: 1,805
bunglebrown is on a distinguished road
Quote  
09-30-2008, 06:52 PM
Re: Image checkbox

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.
Reply With Quote
bunglebrown is offlineReport Post
x10 Sophmore

Salvatos's Avatar

Join Date: Jun 2006
Posts: 226
Credits: 2,052
Salvatos has a spectacular aura about
Location: Québec, Canada

Quote  
09-30-2008, 08:11 PM
Re: Image checkbox

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:
<?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";
}
?>
 
<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="<? 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>
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 by Salvatos; 09-30-2008 at 08:12 PM.
Reply With Quote
Salvatos is offlineReport Post
x10 Sophmore

Join Date: Aug 2008
Posts: 143
Credits: 1,805
bunglebrown is on a distinguished road
Quote  
10-01-2008, 03:27 PM
Re: Image checkbox

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 Code:
<?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";
}
?>
Reply With Quote
bunglebrown is offlineReport Post
x10 Sophmore

Salvatos's Avatar

Join Date: Jun 2006
Posts: 226
Credits: 2,052
Salvatos has a spectacular aura about
Location: Québec, Canada

Quote  
10-01-2008, 07:58 PM
Re: Image checkbox

Yes I think I can see the problem. Here is the fix:

Code:
<?php 
if (isset($_POST['box1']) && $_POST['box1'] != "" && isset($_POST['box2']) && $_POST['box2'] != "") { 
 
// Strip slashes on the Local variables -disabled message field  
$box1  = stripslashes($_POST['box1']);  
$box2  = stripslashes($_POST['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);
 
 
// Boxes empty by default 
$img_box1 = "test/chkbox_empty.png"; 
$img_box2 = "test/chkbox_empty.png"; 
 
// Tick boxes if user has ticked them 
if($box1 == "1"){ 
$img_box1 = "test/chkbox_ticked.png"; 
} 
 
if($box2 == "1"){ 
$img_box2 = "test/chkbox_ticked.png"; 
}
 
exit();  
}
?>
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?
Reply With Quote
Salvatos is offlineReport Post
x10 Sophmore

Join Date: Aug 2008
Posts: 143
Credits: 1,805
bunglebrown is on a distinguished road
Quote  
10-02-2008, 02:32 PM
Re: Image checkbox

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 Code:
<?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();  
?>
Reply With Quote
bunglebrown is offlineReport Post
x10 Sophmore

Salvatos's Avatar

Join Date: Jun 2006
Posts: 226
Credits: 2,052
Salvatos has a spectacular aura about
Location: Québec, Canada

Quote  
10-02-2008, 11:09 PM
Re: Image checkbox

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.
Reply With Quote
Salvatos is offlineReport Post
x10 Sophmore

Join Date: Aug 2008
Posts: 143
Credits: 1,805
bunglebrown is on a distinguished road
Quote  
10-03-2008, 03:46 PM
Re: Image checkbox

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:

Quote:
Box 1
Box 5
Box 6
Box 11
Box 17
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
Reply With Quote
bunglebrown is offlineReport Post
x10 Sophmore

Salvatos's Avatar

Join Date: Jun 2006
Posts: 226
Credits: 2,052
Salvatos has a spectacular aura about
Location: Québec, Canada

Quote  
10-03-2008, 11:57 PM
Re: Image checkbox

I'm gonna post only the end of the code since it's the part concerned. Should be as simple as this:

Code:
<?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
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.";
}
 
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();
?>


Edit: Somehow the CODE tag hates me and **cks up my indentation, so sorry for that.

Last edited by Salvatos; 10-03-2008 at 11:58 PM.
Reply With Quote
Salvatos is offlineReport Post
x10 Sophmore

Join Date: Aug 2008
Posts: 143
Credits: 1,805
bunglebrown is on a distinguished road
Quote  
10-04-2008, 12:09 PM
Re: Image checkbox

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 by bunglebrown; 10-04-2008 at 12:21 PM.
Reply With Quote
bunglebrown is offlineReport Post
x10 Sophmore

Salvatos's Avatar

Join Date: Jun 2006
Posts: 226
Credits: 2,052
Salvatos has a spectacular aura about
Location: Québec, Canada

Quote  
10-04-2008, 12:19 PM
Re: Image checkbox

Hm depends, what is the problem you get with this one and want to avoid?
Reply With Quote
Salvatos is offlineReport Post
Reply

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[java]background image vigge_sWe Programming Help 8 09-13-2008 03:12 PM
3000 credits for header image bigjoe4 The Marketplace 44 05-02-2008 12:35 PM
Looking for a free pdf to image converter Christopher Off Topic 8 01-11-2007 04:50 PM
November Desktop n4tec Off Topic 12 11-08-2005 08:18 AM


All times are GMT -5. The time now is 06:32 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC7
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

Free Games | Debt Consolidation | Mortgages | Internet Advertising | Credit Card Offers