Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2005, 03:42 AM
Authorized User
 
Join Date: Feb 2005
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kumarop
Default upload files in email

Hi All,
Attached are two asp pages which are running fine in seperation. Aim is to make one comprehensive form.In email i want to provide field for uploadation.I have tried,but landed with one or another javascript error.
I want user first upload the file through a button,then main form should be submitted?or suggest what is the best option in this condition.

If you help me to make one comprehensive form it will be great help providing a link on main page and proceed is always a option.

email.asp
Code:
<%@ Language=VBScript %>

<% option explicit %>
<HTML>
<HEAD>
<%
dim conn,ObjCom
%>
<script language="javascript">
function fn_submit()
{
  if (document.forms[0].vto.value==null || document.forms[0].vto.value=="" )
            {
            alert ("to is empty ..");
            document.forms[0].vto.focus();
            return false;
            }
  else if (document.forms[0].vfrom.value==null || document.forms[0].vfrom.value=="" )
            {
            alert ("write your email address ..");
            document.forms[0].vfrom.focus();
            return false;
            }

  else 
      {    
            if(!validemail(document.forms[0].vto.value))
            {
              alert("You need to enter valid email");
              document.forms[0].vto.focus();
              return false;
            }

      document.forms[0].submit();
     }

}

function validemail(str) 
    {
      var strFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
      if (strFilter.test(str))
        { return true; }
      else
        { return false; }
    }


</script>
<%
  If Request.Form("IsSubmitted") <> "" and Request.Form("IsSubmitted") <> "" Then

%>
     <table>
     <tr>
     <td></td>
<%     

                    Dim tcc,tto,tbcc,tsubject,tmessage,tfrom
                    tmessage = Request.Form("vmessage")
                    tto  = Request.Form("vto")
                    tcc = Request.Form("vcc")
                    tbcc = Request.Form("vbcc")
                    tsubject = Request.Form("vsubject")
                    tfrom = Request.Form("vfrom")
                    Const cdoSendUsingPort = 2
                    Dim oConfiguration
                    Dim oMessage
                    Dim oFields
                    Set oMessage = CreateObject("CDO.Message")
                    Set oConfiguration = CreateObject("CDO.Configuration")
                    Set oFields = oConfiguration.Fields
                    With oFields
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") _
                        = cdoSendUsingPort
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
                        = "*.*.1.1" 
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
                          = 100 
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") _
                        = 10 
                    'for priority
                    .Item("urn:schemas:mailheader:X-MSMail-Priority") = 0 
                    .Update
                    End With
                    'Apply the settings to the message.
                         With oMessage
                              Set .Configuration = oConfiguration
                              .To   = tto
                              .Bcc  = tbcc
                              .CC   = tcc
                              .From = tfrom
                              'Request.Form("vfrom")
                              .Subject = tsubject
                              '.HTMLBody = "Password Reset Request From <table border = 1 align =top  cellspacing = 1 cellpadding = 1><TR><td>This Password Reset Request is for Unit : </td><td><b>( " & Message & " )</b></td></tr> <tr ><td>Vendor Code :</td><td><b>" & message_vendorcode & "</b></td></tr><tr><td> Vendor Name :</td><td><b> "& message_vendorname & "</b></td></tr><tr></table><table border = 1 align =top  cellspacing = 1 cellpadding = 1><tr><td><pre>" & tmessage &"</td></tr></pre></table>"
                              .HTMLBody = "<table border = 0 align =top  cellspacing = 1 cellpadding = 1><tr><td><pre>" & tmessage &"</td></tr></pre></table>"
                              '.CreateMHTMLBody ("c:\test.doc")    
                              '.AddAttachment ("C:\sample.jpg")
                              .Send
                         End With
                    'Clean up variables.
                    Set oMessage = Nothing
                    Set oConfiguration = Nothing
                    Set oFields = Nothing

%>
                    <script language = "javascript">    
                    alert("Mail Sent Sucessfully");
                    </script>
</table>
<%   
       End If                     
%>
</HEAD>
<BODY>
<form id="frmSendEmail" name="frmSendEmail" method="post" action=<%=request.servervariables("script_name")%>>
    <table border = "0" align ="top"  cellspacing = 1 cellpadding = 1 width = "80%">
    <tr><td ALIGN=middle valign = top colspan =2>  Send Email&nbsp; </td></tr>

    <tr><td align=middle valign =top colspan=2><b>To prevent abuse, your IP Address (<%= Request.ServerVariables("http_host")%>)will be logged and recorded for this email message..</b></td></tr>

    <tr bgcolor="#eeeeee">      
          <td align = left rowspan = 6 width = "30%">Your email:<BR><input name = "vfrom" id = "vfrom" 
      style="WIDTH: 179px; HEIGHT: 22px" size=23> * <BR><%=now()%>(MM/DD/YYYY)</td></tr>

    <tr bgcolor="#eeeeee"> 
         <td ALIGN=left><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      To:&nbsp;<input name="vto" id="vto" style="WIDTH: 396px; HEIGHT: 22px" size=48></STRONG></td></tr>
   <tr bgcolor="#eeeeee">
        <td ALIGN=left><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      &nbsp;cc:</STRONG><input name="vcc" id="vcc" style="WIDTH: 396px; HEIGHT: 22px" size=49></td></tr>
   <tr bgcolor="#eeeeee">
        <td align=left><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      bcc:</STRONG><input name="vbcc" id="vbcc" style="WIDTH: 396px; HEIGHT: 22px" size=48> </td></tr>
   <tr bgcolor="#eeeeee">
        <td ALIGN=left valign = top><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      Subject:</STRONG><input name="vsubject" id="vsubject" style="WIDTH: 396px; HEIGHT: 22px" size=46></td></tr>

   <tr bgcolor="#eeeeee">     
        <td align=left colspan=3><strong>Upload File:</strong><input type=file name=YourFile  size=35><input type=submit name=submit value="Upload"></td></tr>  

    <tr bgcolor="#eeeeee">
        <td ALIGN=left colspan=2><STRONG>Your message:</STRONG> </td></tr>
    <tr bgcolor="#eeeeee">
        <td align = left colspan =2><TEXTAREA id=vmessage name=vmessage rows=5 wrap=physical cols=80></TEXTAREA></td></tr><br>
    <tr bgcolor="#eeeeee"><td align=left colspan=2><input type="button" name="btnSubmit" id="btnSubmit"
          value="Send Message" onclick="fn_submit()" > </td></tr>
    <tr bgcolor="white">
         <td  align = middle colspan=3><p><A href="JavaScript:onClick=window.close()">Close Window</A></p>
    </td></tr>      
</table>
<input type="hidden" value= "True" name="IsSubmitted" >
</form>            

</BODY>
</HTML>

email_process_file.asp
Code:
<%@ Language=VBScript %>

<form method=post
      enctype="multipart/form-data"
      action=<%=request.servervariables("script_name")%>>
Your File:<input type=file name=YourFile>
<input type=submit name=submit value="Upload" >
</form>
<%
Dim objUpload, lngLoop,filename,filename1

If Request.TotalBytes > 0 Then
    Set objUpload = New vbsUpload

  For lngLoop = 0 to objUpload.Files.Count - 1
    'If accessing this page annonymously,
    'the internet guest account must have
    'write permission to the path below.
    strPath=Server.MapPath("uploaded")
    objUpload.Files.Item(lngLoop).Save "c:\temp\"
    filename = objUpload.Files.Item(lngLoop).FileName()
    filename1 = escape(filename)
    'urltogo = "/table_import.asp?table=" & filename1
    'Response.Redirect urltogo

    Response.Write "File Uploaded"
    Next

End if
%>


om prakash kumar
__________________
om prakash kumar





Similar Threads
Thread Thread Starter Forum Replies Last Post
Upload pdf files yanis97 JSP Basics 3 April 23rd, 2007 11:43 PM
cant upload files akber ASP.NET 1.0 and 1.1 Basics 3 November 6th, 2006 03:06 AM
How to upload multiple Files at once hwsc VB How-To 1 January 23rd, 2005 12:45 PM
upload files joeore PHP Databases 9 February 15th, 2004 05:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.