PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 28th, 2002, 08:59 PM
Myst Myst is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 Myst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Mail form with checkbox array...

Hello, I am a total newbie at php. So you make look at this and think that's it's soooo simple. Here it goes. I have a contact sheet of pictures that I want the user to be able to select with checkboxes and also enter a comment bellow about the picture. On submit I would like the selections to be mailed to me. So I've named all my checkboxes:

<input type="checkbox" name="selection[]" value="0001"> 0002, 0003, etc.

and I did my php code like this:

<?php

$msg = "Item Selected:tforeach($_POST[selection] as $value)n";

$recipient = "design@media-glyphics.com";
$subject = "Contact Sheet Form";

$mailheaders = "From: My Web Site <> n";

mail($recipient, $subject, $msg, $mailheaders);

echo "<HTML><HEAD><TITLE>Form Sent!</TITLE></HEAD><BODY>";
echo "<H1 align=center>Thank You, $_POST[sender_name]</H1>";
echo "<P align=center>Your feedback has been sent.</P>";
echo "</BODY></HTML>";

?>

Here is a link to the actual contact sheet with pictures: http://clients.media-glyphics.com/ama/contact_sheet.htm

I don't have anything writen for the "comments" box yet, as I'm just trying to figure out this problem right now, but if you would like to touch on that too, that would be great.
If anyone could help me with this I would be very gratefull. Thank you muchly.

~Myst~

Reply With Quote
  #2  
Old August 28th, 2002, 10:31 PM
guyer guyer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bloomington, IN USA
Posts: 47 guyer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to guyer
RE: Mail form with checkbox array...

I'll include the whole comment deal:
Name your textareas in a similar fashion:

<input type="checkbox" name="selection[]" value="0001">
<textarea name="comment[]" cols="15">Comments</textarea>

For the message:

<?
$msg="Items Selected:nn";
for($i=0;$i<count($_POST['selection']);$i++){
$msg.="t$_POST['selection'][$i]t$_POST['comment'][$i]n";
}
?>

Reply With Quote
  #3  
Old August 28th, 2002, 10:31 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Mail form with checkbox array...

try it like this
php Code:
Original - php Code
  1.  
  2. <?php
  3. $msg = "Item Selected:tn";
  4. foreach($_POST['selection'] as $value)
  5. {
  6.     $msg .= "$valuen";
  7. }
  8. ?>

Reply With Quote
  #4  
Old August 28th, 2002, 10:35 PM
guyer guyer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bloomington, IN USA
Posts: 47 guyer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to guyer
RE: Mail form with checkbox array...

Actually, mine's broken. You'd have to do this:
Code:
<?
$msg="Items Selected:nn";
for($i=0;$i<count($_POST['selection']);$i++){
   $msg.="t".$_POST['selection'][$i]."t".$_POST['comment'][$i]."n";
}
?>

Reply With Quote
  #5  
Old August 29th, 2002, 09:55 PM
Myst Myst is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 Myst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Mail form with checkbox array...

Thank you both for your help. I got it up and going thanks to your suggestions.

~Myst~

Reply With Quote
  #6  
Old August 30th, 2002, 01:36 AM
Myst Myst is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 Myst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Mail form with checkbox array...

Hello, I got the first part of the code to work, no problem. The part that doesn't quite work is the 'comments'. All it will submit is the first comment, anything after that is left off. I need it to submit all comments with their respective pictures. It seems that it should be something like this:

<?php

$msg="Items Selected:nn";
for($i=0;$i<count($_POST['selection']);$i++),($i=0;$i<count($_POST['comment']);$i++){
$msg.="t".$_POST['selection'][$i]."t".$_POST['comment'][$i]."n";
}

$recipient = "design@media-glyphics.com";
$subject = "Contact Sheet Form";

$mailheaders = "From: Contact Sheet Form <> n";

mail($recipient, $subject, $msg, $mailheaders);

echo "<HTML><HEAD><TITLE>Form Sent!</TITLE></HEAD><BODY>";
echo "<H1 align=center>Thank You, $_POST[sender_name]</H1>";
echo "<P align=center>Your selction has been sent.</P>";
echo "</BODY></HTML>";

?>

to include both arrays of 'selection' and 'comment' right? Anyways, I'm doing it wrong cause it won't work. I have some sort of syntax wrong to seperate the two formulas. Should they both be in brackets or seperated with a semi-colon?? Maybe I have the WHOLE thing wrong. I understand the logic of it but I don't know how to speak the language. Thanks again for any suggestions you may have...

~Myst~

Reply With Quote
  #7  
Old August 30th, 2002, 01:43 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Mail form with checkbox array...

try seperating your selection and comment arrays into separate for loops. know what i mean?

Reply With Quote
  #8  
Old August 30th, 2002, 11:57 PM
Myst Myst is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 Myst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Mail form with checkbox array...

Thank you again for your help, the two 'for' loops worked and I got a correct submission. The only problem I have now is proper formating. This is the code that I used:

<?php

$msg="Items Selected:nn";
for($i=0;$i<count($_POST['selection']);$i++){
$msg.="t".$_POST['selection'][$i]."n";
}
for($i=0;$i<count($_POST['comment']);$i++){
$msg.="t".$_POST['comment'][$i]."n";
}

$recipient = "kandy@media-glyphics.com";
$subject = "Contact Sheet Form";

$mailheaders = "From: Contact Sheet Form <> n";

mail($recipient, $subject, $msg, $mailheaders);

echo "<HTML><HEAD><TITLE>Form Sent!</TITLE></HEAD><BODY>";
echo "<H1 align=center>Thank You,</H1>";
echo "<P align=center>Your selction has been sent.</P>";
echo "</BODY></HTML>";

?>

And this is the response that I got via email:


Items Selected:

0014
0016
0017
0022













14 test

16 test
17 test




22 test

I typed in the '14 test' etc. in the comment box. When it parses the 'comment' string it includes empty spaces that are in the comment boxes. I would like to eliminate those empty spaces somehow. I tried using the trim($comment) command, but it didn't work.? Is that the right way to go? Ideally it would be great if the comment for 0014 were right next to it's selected number, but that's just me being picky. Thank you for all your help so far, and if you don't have time for this one, it's ok. I did get it working at least, I can deal with the mile long email with empty spaces if I have to. Thanks again.

~Myst~

Reply With Quote
  #9  
Old August 31st, 2002, 04:27 AM
webhappy webhappy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Silicon Valley, CA, USA
Posts: 203 webhappy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Mail form with checkbox array...

I believe you're .= even when it's empty.

On the second for-loop (through the comments), do a
if ( !empty($arrayofComments) )
first, so it skips the empty ones.

Reply With Quote
  #10  
Old August 31st, 2002, 10:22 PM
Myst Myst is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 Myst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Mail form with checkbox array...

ok, I think that I have the logic now, but I'm writing it wrong. When I tried the previous suggestion, it completly ignored anything entered in the comments box. Maybe I wrote it wrong:

$msg="Items Selected:nn";
for($i=0;$i<count($_POST['selection']);$i++){
$msg.="t".$_POST['selection'][$i]."n";
}
if (!empty($comment));
for($i=0;$i<count($_POST['comment']);$i++){
$msg.="t".$_POST['comment'][$i]."n";
}


I also tried something like this:

$msg="Items Selected:nn";
for($i=0;$i<count($_POST['selection']);$i++){
$msg.="t".$_POST['selection'][$i]."n";
}

$empty_space="";

if ($comment != $empty_space) ){
for($i=0;$i<count($_POST['comment']);$i++){
$msg.="t".$_POST['comment'][$i]."n";
}
}

I set up the variable of $empty_space to represent a blank "". Then I told it, that if $comment does not equal an $empty_space then continue through the 'for' loop. Am I wrong in this?

~Myst~

Reply With Quote
  #11  
Old September 1st, 2002, 05:19 PM
webhappy webhappy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Silicon Valley, CA, USA
Posts: 203 webhappy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Mail form with checkbox array...

Er...

I meant this:

for($i=0;$i<count($_POST['comment']);$i++)
if ( !empty($_POST['comment']) )
$msg.="t".$_POST['comment'][$i]."n";


Reply With Quote
  #12  
Old September 1st, 2002, 07:30 PM
Myst Myst is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 Myst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Mail form with checkbox array...

Hello again,
Your suggestion didn't work. It still submitted blank spaces along with the comments. I tried this, but it did the same thing:

$blank_comment="Comment here";

for($i=0;$i<count($_POST['comment']);$i++){
if ($_POST['comment'] != $blank_comment){
$msg.="t".$_POST['comment'][$i]."n";
}
}

I replaced the empty comments boxes on the html page with a phrase "Comment here" so that I would have something to reference with $blank_comment. I thought that if I told it that "only if $_POST['comment'] did not equal $blank_comment - then submit the selection", but apparently it didn't see it that way as this is what I got back:

Items Selected:

0002
0003
0005
0007
Comment here
2222222222
333333333333
Comment here
5555555555
Comment here
7777777777
Comment here
Comment here
Comment here
Comment here
Comment here
Comment here
etc......

So, I'm stumped. This is my first poke at php, and I have to say that I've learned a lot so far. Thanks for your suggestions though. ;)

~Myst~

Reply With Quote
  #13  
Old September 1st, 2002, 09:43 PM
webhappy webhappy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Silicon Valley, CA, USA
Posts: 203 webhappy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Mail form with checkbox array...

Ah, I'm sorry... I have no idea right now

I would try print_r($_POST['comments']) to see what exactly it's holding... hm...

Reply With Quote
  #14  
Old September 2nd, 2002, 11:02 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Mail form with checkbox array...

your idea will work, you just forgot to reference the array element. try this
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. $blank_comment = "Comment here";
  5.  
  6. for($i=0; $i<count($_POST['comment']); $i++)
  7. {
  8.     if ($_POST['comment'][$i] != "$blank_comment")
  9.     {
  10.         $msg .= "t".$_POST['comment'][$i]."n";
  11.     }
  12. }
  13.  
  14. ?>

Reply With Quote
  #15  
Old September 2nd, 2002, 11:14 PM
Myst Myst is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7