Go Back   Novahq.net Forum > phphq.Net > phphq.Net Forums

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-18-2008, 06:52 PM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

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
Reply With Quote
  #2  
Old 10-19-2008, 01:01 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
http://www.webcheatsheet.com/PHP/sen...php#attachment
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy
Reply With Quote
  #3  
Old 10-19-2008, 01:24 PM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

Im sorry, but i really don't know what to do with that. Do you care to explain? :-)
Reply With Quote
  #4  
Old 10-20-2008, 06:35 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
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>
<form action="phMailer.php" method="post" enctype="multipart/form-data">
<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>
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy

Last edited by atholon; 10-20-2008 at 06:51 PM.
Reply With Quote
  #5  
Old 10-20-2008, 08:16 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
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>
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy
Reply With Quote
  #6  
Old 10-21-2008, 08:49 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
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>
<?}?>
With:
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>
3. Replace code starting on 486
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>
With this:
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>
And you should be good to go.
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy

Last edited by atholon; 10-24-2008 at 06:49 PM.
Reply With Quote
  #7  
Old 10-22-2008, 10:37 AM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

Thanks mate, I'm going to try it out and then I'll get back to you with the result!

F
Reply With Quote
  #8  
Old 10-22-2008, 02:52 PM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

Thank you Atholon, it works like a charm.
Reply With Quote
  #9  
Old 10-22-2008, 03:32 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
No problem

Sorry I didn't understand it at first.
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy
Reply With Quote
  #10  
Old 10-23-2008, 07:58 PM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

Quote:
Originally posted by atholon
No problem

Sorry I didn't understand it at first.
It seems like it did not work after all. When i send an email from the form, i only get one attachment, probably because I have set allowed number of attachments to 1 in the beginning of the script. And if i set it to zero, the button that you, Atholon, created for me does not show.

So, what should I do?

/F
Reply With Quote
  #11  
Old 10-23-2008, 08:04 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
change $allowattach="1"; to $allowattach = "10";

odd that it is a string but what the hay.
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy
Reply With Quote
  #12  
Old 10-24-2008, 05:38 AM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

Quote:
Originally posted by atholon
change $allowattach="1"; to $allowattach = "10";

odd that it is a string but what the hay.
Well I did that too, but then I just got 10 fields with an "add extra attachment"-button under each field..

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..
Attached Images
File Type: jpg formsample.jpg (33.7 KB, 6 views)

Last edited by Frizzo; 10-24-2008 at 05:55 AM.
Reply With Quote
  #13  
Old 10-24-2008, 05:32 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
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.
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy
Reply With Quote
  #14  
Old 10-24-2008, 05:40 PM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

Quote:
Originally posted by atholon
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.
I really appreciate the help! So you think you can fix it?

/F
Reply With Quote
  #15  
Old 10-24-2008, 06:37 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
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.
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy

Last edited by atholon; 10-24-2008 at 06:44 PM.
Reply With Quote
  #16  
Old 10-24-2008, 06:49 PM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

I thank you for your effort, but it still does not work. Looks (and works) exactly like before..

**** it, I'll get another form..
Reply With Quote
  #17  
Old 10-24-2008, 06:50 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
Try using my version and then just change it to what you want.

I will upload it in a second.
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy
Reply With Quote
  #18  
Old 10-24-2008, 06:55 PM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

Sure!
Reply With Quote
  #19  
Old 10-24-2008, 06:57 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,351

Send a message via MSN to atholon
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.
__________________

My site: http://www.codeprotocol.com
"Bro, you are so full of win, if I slashed you with a kitchen knife, you'd be bleeding awesomeness." - Chrispy
Reply With Quote
  #20  
Old 10-24-2008, 07:11 PM
Frizzo is offline Frizzo
Registered User

Join Date: Sep 2008
Posts: 13

It works fine now, I must have messed something up on my own.

Thanks!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

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


All times are GMT -5. The time now is 05:38 AM.




Powered by vBulletin®