#1
|
||
|
Phmailer file attachment options
Hi!
I use the Phmailer as an contact form, and I need the user to be able to choose how many attachment fields the user needs. Currently I have it set to 10 fields, but it looks a bit too much. And i really need like 10 or 15 fields. How do i create a drop down menu for the number of attachment fields that i want the customer to be able to choose from? / Frizzo from Sweden |
#2
|
||
|
__________________
|
#3
|
||
|
Im sorry, but i really don't know what to do with that. Do you care to explain? :-)
|
#4
|
||
|
Sorry I misunderstood the question.
You'd do that in javascript. I will post an example in a minute. Code:
<script language="javascript"> var attachbutton = document.getElementById("addextraattach"); if (attachbutton) { attachbutton.onclick = addField; } function addField() { var attachBox = document.createElement("input"); attachBox.type = "file"; attachBox.name = "attachments[]"; var attachments = document.getElementById("attachmentdiv"); if (attachments) { attachments.appendChild(attachbox); } } </script> <p>Attachments <input type="file" name="pictures[]" /> <div id="attachmentdiv"></div><input type="button" value="Add Another Attachment" id="addextraattach" /> <input type="submit" value="Send" /> </p> </form>
__________________
Last edited by atholon; 10-20-2008 at 06:51 PM. |
#5
|
||
|
Here we go:
Code:
<html> <head> <script type="text/javascript"> function init() { var attachbutton = document.getElementById("addextraattach"); if (attachbutton) { attachbutton.onclick = addField; } } function addField() { allowedFiles = 10; if (!addField.count) { addField.count = 1; } else { addField.count++; } if (addField.count < allowedFiles) { var boxDiv = document.createElement("div"); var box = document.createElement("input"); box.type = "file"; box.name = "attachments[]"; boxDiv.appendChild(box); var attachments = document.getElementById("attachmentdiv"); if (attachments) { attachments.appendChild(boxDiv); } } else { alert("You can only add "+allowedFiles+" files!"); } } </script> </head> <body onload="javascript:init();"> <form action="phMailer.php" method="post" enctype="multipart/form-data"> <div>Attachments</div> <div> <input type="file" name="attachments[]" /> <div id="attachmentdiv"></div><input type="button" value="Add Another Attachment" id="addextraattach" /> </div> <span><input type="submit" value="Send" /></span> </form> </body> </html>
__________________
|
#6
|
||
|
Oh sorry, I have not used scott's script for a while, here's what you do:
1. Go to line 577 of phMailer.php 2. Replace: Code:
<?For($i=1;$i <= $allowattach; $i++) {?> <tr> <td width="30%" class="table_body">Attach File:</td> <td width="70%" class="table_body"><input name="attachment[]" type="file" size="30" /></td> </tr> <?}?> Code:
<tr> <td width="30%" class="table_body">Attach File:</td> <td width="70%" class="table_body"><div id="attachmentdiv"><input name="attachment[]" type="file" size="30" /></div> </td> </tr> <tr> <td colspan="2" class="table_body"><input type="button" value="Add Another Attachment" id="addextraattach" /> </td> </tr> Code:
<script type="text/javascript"> var error=""; e_regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/; function Checkit(theform) { if(theform.yourname.value=="") { error+="You did not enter your name\n"; } if(theform.youremail.value=="") { error+="You did not enter your email\n"; } else if(!e_regex.test(theform.youremail.value)) { error+="Invalid email address\n"; } if(theform.yourmessage.value=="") { error+="You did not enter your message\n"; } if(error) { alert('**The form returned the following errors:**\n\n' + error); error=""; return false; } else { return true; } } </script> Code:
<script type="text/javascript"> var error=""; e_regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/; function Checkit(theform) { if(theform.yourname.value=="") { error+="You did not enter your name\n"; } if(theform.youremail.value=="") { error+="You did not enter your email\n"; } else if(!e_regex.test(theform.youremail.value)) { error+="Invalid email address\n"; } if(theform.yourmessage.value=="") { error+="You did not enter your message\n"; } if(error) { alert('**The form returned the following errors:**\n\n' + error); error=""; return false; } else { return true; } } function init() { var attachbutton = document.getElementById("addextraattach"); if (attachbutton) { attachbutton.onclick = addField; } } function addField() { allowedFiles = <?php echo $allowattach;?> ; if (!addField.count) { addField.count = 1; } else { addField.count++; } if (addField.count < allowedFiles) { var boxDiv = document.createElement("div"); var box = document.createElement("input"); box.type = "file"; box.name = "attachment[]"; box.size = "30"; boxDiv.appendChild(box); var attachments = document.getElementById("attachmentdiv"); if (attachments) { attachments.appendChild(boxDiv); } } else { alert("You can only add "+allowedFiles+" files!"); } } window.onload = init; </script>
__________________
Last edited by atholon; 10-24-2008 at 06:49 PM. |
#7
|
||
|
Thanks mate, I'm going to try it out and then I'll get back to you with the result!
F |
#8
|
||
|
Thank you Atholon, it works like a charm.
|
#9
|
||
|
No problem
Sorry I didn't understand it at first.
__________________
|
#10
|
|||
|
Quote:
So, what should I do? /F |
#11
|
||
|
change $allowattach="1"; to $allowattach = "10";
odd that it is a string but what the hay.
__________________
|
#12
|
|||
|
Quote:
Here, take a look. The text is in Swedish but I tink you'll get the picture anyway. Edit: It says, when i have added 10 fields that "You can only add 10 files!", but it does not send the extra added nine attachments.. It's hard to explain.. Last edited by Frizzo; 10-24-2008 at 05:55 AM. |
#13
|
||
|
I will have to look more into how he implements it in his script.
It should only have one "add another attachment" button if you used my code.
__________________
|
#14
|
|||
|
Quote:
/F |
#15
|
||
|
OK dude, it is because I made the input name attachments[] try attachment[] I have it updated in the above code.
I also fixed some styling issues, I never really tested it out but I just gave it a shot and it is working fine. You can change same var that scott added to change the number of files that can be attached.
__________________
Last edited by atholon; 10-24-2008 at 06:44 PM. |
#16
|
||
|
I thank you for your effort, but it still does not work. Looks (and works) exactly like before..
**** it, I'll get another form.. |
#17
|
||
|
Try using my version and then just change it to what you want.
I will upload it in a second.
__________________
|
#18
|
||
|
Sure!
|
#19
|
||
|
http://digitalhelpfiles.com/phMailer.zip
Scott, if you want to look this over and post it on your site that's cool. I just don't want you to get pissed off for me putting it on my server. If you're still having problems with that one I sent then you have something else messed up because I just tested it twice and it sent two attachments.
__________________
|
#20
|
||
|
It works fine now, I must have messed something up on my own.
Thanks! |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Attachment Not Attaching on phMailer Form | Gazza | phphq.Net Forums | 4 | 04-12-2010 02:31 AM |
Send Email with Attachment from the File Upload | ronieperez | phphq.Net Forums | 2 | 10-24-2008 07:14 PM |
phMailer File Attachment Label | jamesr | phphq.Net Forums | 0 | 08-13-2008 03:13 AM |
attachment again... | Guest | phphq.Net Forums | 0 | 07-18-2005 02:49 AM |
phMailer attachment | Fallu | phphq.Net Forums | 3 | 12-25-2004 01:09 AM |