|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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~ |
|
#2
|
|||
|
|||
|
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"; } ?> |
|
#3
|
|||
|
|||
|
RE: Mail form with checkbox array...
|
|
#4
|
|||
|
|||
|
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";
}
?>
|
|
#5
|
|||
|
|||
|
RE: Mail form with checkbox array...
Thank you both for your help. I got it up and going thanks to your suggestions.
~Myst~ |
|
#6
|
|||
|
|||
|
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. ~Myst~ |
|
#7
|
|||
|
|||
|
RE: Mail form with checkbox array...
try seperating your selection and comment arrays into separate for loops. know what i mean?
|
|
#8
|
|||
|
|||
|
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. ~Myst~ |
|
#9
|
|||
|
|||
|
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. |
|
#10
|
|||
|
|||
|
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~ |
|
#11
|
|||
|
|||
|
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"; |
|
#12
|
|||
|
|||
|
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~ |
|
#13
|
|||
|
|||
|
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... |
|
#14
|
|||
|
|||
|
RE: Mail form with checkbox array...
|
|
#15
|
|||
|