Foros del Web » Creando para Internet » HTML »

formulario / enviar archivos adjuntos en html

Estas en el tema de formulario / enviar archivos adjuntos en html en el foro de HTML en Foros del Web. Hola..necesito hacer un formulario de contacto en html..nunca hice uno..y ademas, tengo qeu agregarle la posibilidad de que se pueda enviar un archivo adjunto. alguien ...
  #1 (permalink)  
Antiguo 04/10/2007, 19:48
Avatar de lrecchia  
Fecha de Ingreso: diciembre-2005
Mensajes: 214
Antigüedad: 18 años, 4 meses
Puntos: 2
formulario / enviar archivos adjuntos en html

Hola..necesito hacer un formulario de contacto en html..nunca hice uno..y ademas, tengo qeu agregarle la posibilidad de que se pueda enviar un archivo adjunto.
alguien me puede ayudar por favor????
gracias'¡¡¡
  #2 (permalink)  
Antiguo 05/10/2007, 08:13
 
Fecha de Ingreso: octubre-2007
Ubicación: en santiago chile
Mensajes: 34
Antigüedad: 16 años, 6 meses
Puntos: 0
Re: formulario / enviar archivos adjuntos en html

tengo algo en asp, es un formulario que se puede adapatar y tiene la posibilidad de subir archivos, son tres paginas, el formulario, el que recibe y guarda el formulario y uno que se encarga de los archivos que agregas loader.asp

la primera pagina
formulario.asp

<html>
<head>
<title>AGREGAR PRENSA</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="texto.css" rel="stylesheet" type="text/css">
<script language="JavaScript1.2">
<!--
//*****
var primeraVez = true;

function limpia(){
if (primeraVez){
document.form1.txt_Detalle.value = "";
primeraVez = false;
}
}

function cuenta(){
document.form1.total.value = document.form1.txt_Detalle.value.length;
maximo()
}
function maximo(){
var VMaximo
VMaximo = document.form1.txt_Detalle.value.length;
if (VMaximo >50 ){
alert("Sobre paso el maximo de caracteres permitidos")
cadena = document.form1.txt_Detalle.value
//alert(cadena)
cadena = cadena.substring(0,51-1)
document.form1.txt_Detalle.value = cadena
document.form1.txt_principal.focus();
}
}
//****
function validanoticia(){
if (document.form1.txt_titulo.value.length== 0){
alert('El campo titulo no puede estar vacio');
document.form1.txt_titulo.focus();
return (false);
}
if (document.form1.txt_Detalle.value.length== 0){
alert('El campo detalle no puede estar vacio');
document.form1.txt_Detalle.focus();
return (false);
}
if (document.form1.dia.value == 0){
alert('Debe seleccionar una dia');
document.form1.dia.focus();
return (false);
}
if (document.form1.Mes.value == 0){
alert('Debe seleccionar una mes');
document.form1.Mes.focus();
return (false);
}
if (document.form1.Ano.value == 0){
alert('Debe seleccionar una año');
document.form1.Ano.focus();
return (false);
}
if(document.form1.seleccion.value == 0){
alert('debe ingresar un documento');
document.form1.seleccion.focus();
return (false);
}
if (document.form1.publica.checked == false){
if (confirm("Si no selecciona la opción publica solo se grabara la noticia")){
document.form1.publica.click()
return (false);
}
}



}
-->
</script>
</head>
<body background="../../imagenes/fondo_noticias.gif">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="middle">
<td width="33%" height="14" bgcolor="#FBE9A4">
<div align="center" class="titulos"> </div></td>
<td width="33%" bgcolor="#FBE9A4">
<div align="center" class="titulos"> AGREGAR PRENSA </div></td>
<td width="33%" bgcolor="#FBE9A4" class="mensajes" colspan="3">
<div align="center"></div></td>
</tr>
</table>
<BR>
<form name="form1" action="guardar_archivo2.asp" target="mainFrame" enctype="multipart/form-data" method="post" onSubmit="return validanoticia(this)">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="21%" valign="bottom"><div align="right"> <p class="texto" style="margin-right: 10; margin-top: 0; margin-bottom: 0">Fecha Noticia:</p>
</div></td>
<td width="79%" class="texto">Dia
<select name="dia" class="bored">
<option value="0">Día</option>
<%for Dia = 1 to 31 step 1 %>
<option <%if Dia = Day(now) then%> selected <%end if%> value="<%=Dia%>" <%
'if Ro_Dia = Dia then
' response.write("selected")
'end if%>><%=Dia%></option>
<%next%>
<% Dim Ames(12)
Ames(1) = "Enero"
Ames(2) = "Febrero"
Ames(3) = "Marzo"
Ames(4) = "Abril"
Ames(5) = "Mayo"
Ames(6) = "Junio"
Ames(7) = "Julio"
Ames(8) = "Agosto"
Ames(9) = "Septiembre"
Ames(10) = "Octubre"
Ames(11) = "Noviembre"
Ames(12) = "Diciembre"
%>
</select>
Mes
<select name="Mes" class="bored">
<option value="0">Mes</option>
<%for i= 1 to 12 step 1 %>
<option value="<%=i%>" <%
if i = month(now) then
response.write("selected")
end if%>><%=Ames(i)%></option>
<%next%>
</select>
Año
<select name="Ano" class="bored">
<option selected value="0">Año</option>
<%for i= (year(now())+1) to 2003 step -1 %>
<option value="<%=i%>" <%
if i = year(now()) then
response.write("selected")
end if
%>><%=i%></option>
<%next%>
</select></td>
</tr>
<tr>
<td><div align="right"><p class="texto" style="margin-right: 10; margin-top: 0; margin-bottom: 0">Titulo:</p>
</div></td>
<td><p style="margin-left: 10; margin-top: 5; margin-bottom: 5">
<input name="txt_titulo" type="text" class="bored" size="50" maxlength="40">
</p>
</td>
</tr>
<tr>
<td valign="top"><div align="right"><p class="texto" style="margin-right: 10; margin-top: 0; margin-bottom: 0">Detalle:</p>
</div></td>
<td><p style="margin-left: 10; margin-top: 0; margin-bottom: 5"><!-- onFocus="limpia()" onKeyUp="cuenta()" onKeyPress="cuenta()" -->
<textarea name="txt_Detalle" cols="60" rows="8" class="bored"></textarea>
<!--<input type="text" name="total" size="2" maxlength="3" disabled>-->
<!--<font color="#660000" size="1" face="Verdana, Arial, Helvetica, sans-serif">(Max.
de carasteres 39) </font>--></p>
<p></p></td>
</tr>

<!-- <tr>
<td><div align="right"><p class="texto" style="margin-right: 10; margin-top: 0; margin-bottom: 0">Ubicación:</p>
</div></td>
<td> <p style="margin-left: 10; margin-top: 0; margin-bottom: 5">
<select name="ubicacion">
<option value="0">::Seleccione::</option>
<option value="1">1</option>
<option value="2">2</option>
</select></p></td>
</tr>-->
<tr>
<td><div align="right"><p class="texto" style="margin-right: 10; margin-top: 0; margin-bottom: 0">Publica:</p>
</div></td>
<td><p style="margin-left: 10; margin-top: 0; margin-bottom: 5">
<input name="publica" type="checkbox" value="Si"></p>
</td>
</tr>
<tr>
<td><div align="right"><p class="texto" style="margin-right: 10; margin-top: 0; margin-bottom: 0">Seleccionar Documento:</p>
</div></td>
<td> <p style="margin-left: 10; margin-top: 0; margin-bottom: 5">
<input type="file" name="seleccion" style="font-family: Verdana; font-size: 8pt" maxlength="200" size="25"></td>
</tr>
<tr>
<td height="23" colspan="2" align="center">
<input name="Grabar" type="submit" id="Grabar" value="Grabar" style="font-family: Verdana; font-size: 8pt">
&nbsp;&nbsp;&nbsp;&nbsp; <input name="Restablecer" type="reset" id="Restablecer" value="Restablecer" style="font-family: Verdana; font-size: 8pt">
</td>
</tr>
</table>
</form>
</body>
</html>
  #3 (permalink)  
Antiguo 05/10/2007, 08:14
 
Fecha de Ingreso: octubre-2007
Ubicación: en santiago chile
Mensajes: 34
Antigüedad: 16 años, 6 meses
Puntos: 0
Re: formulario / enviar archivos adjuntos en html

pagina guardar_archivo2.asp


<!--#include file="Loader.asp"-->
<%
'load object
Dim load
Set load = new Loader
' calling initialize method
load.initialize
'Ot = load.form("Ot")
'Id_Ot = request.QueryString("id")
'----------------------------------- url_boceto --------------------------------------------
titulo=load.getValue("txt_titulo")
DetalleT=load.getValue("txt_Detalle")
dia = load.getValue("dia")
Mes = load.getValue("Mes")
ano = load.getValue("Ano")
VFecha = dia & "/" & mes & "/" & ano

'NomArch=load.getValue("seleccion")
publica=load.getValue("publica")
'0comentario=replace(comentario,chr(13),"")
'comentario=replace(comentario,chr(10),"")

' File binary data
Dim fileData, fileData2
fileData = load.getFileData("seleccion")

' File name
Dim fileName
fileName = LCase(load.getFileName("seleccion"))


' File path
Dim filePath
filePath = load.getFilePath("seleccion")
' File path complete
Dim filePathComplete
filePathComplete = load.getFilePathComplete("seleccion")

' File size
Dim fileSize
fileSize = load.getFileSize("seleccion")
' File size translated
Dim fileSizeTranslated
fileSizeTranslated = load.getFileSizeTranslated("seleccion")
' Content Type
Dim contentType
contentType = load.getContentType("seleccion")


'sql2="select max(id_prensa) from Prensa"
'response.write(id_archivo)

'set rs2 = Server.CreateObject("ADODB.Recordset")
'rs2.open SQL2, conn, 3, 3
'id_archivo=rs2(0)

'SQL3="select max(nombre_archivo) from prensa"
'set rs3 = Server.CreateObject("ADODB.Recordset")
'rs3.open SQL3, conn, 3, 3
'nombre=rs3(0)


'----------------------------------------------------------


Dim pathToFile
NomArch = id_archivo &"_"& fileName
pathToFile = Server.mapPath("Archivador/") & "\" & NomArch
'response.write pathToFile
'response.End()

' Uploading file data
Dim fileUploaded
fileUploaded = load.saveToFile ("seleccion", pathToFile)

'-------------------------------------------------------------------------------------
' No. of Form elements
Dim countElements
countElements = load.Count


Set load = Nothing


set Conn=Server.CreateObject("ADODB.Connection")
Conn.open "DSN=convivir"
'----Insertamos los datos a la BD---------------------------------------------------------------------
sql2 = "insert into Prensa (Titulo,detalle,Fecha_publicado,nombre_archivo,est ado) values("
sql2 = sql2 & "'" & trim(titulo) & "',"
sql2 = sql2 & "'" & trim(DetalleT) & "',"
sql2 = sql2 & "#" & trim(VFecha) & "#"
sql2 = sql2 & ",'" & trim(NomArch) & "',"
sql2 = sql2 & "'" & trim(publica) & "')"
'response.write sql2
'response.End()

On Error resume Next

conn.execute(sql2)

%>
<%
If Err.Number <> 0 then %>
<body background="../../imagenes/fondo_noticias.gif">
<table align="center" width="100%">
<tr>
<td width="33%" bgcolor="#FBE9A4"> <div align="center">
<p class="titulos">ADMINISTRADOR</p>
</div></td>
<td width="33%" bgcolor="#FBE9A4"> <div align="center">
<p class="titulos">CONVIVIR</p>
</div></td>

</tr>
<tr>
<td class="titulos" colspan="2" headers="30%"><div align="center" class="texto">
<p>&nbsp;</p>
<p>Error al subir el archivo</p>
</p>
</div></td>
</tr>
<tr>

<td class="titulos" colspan="2" headers="30%"><div align="center" class="texto"><a href="Agregarprensa.asp">intentar nuevamente</a></div></td>
</tr>
</table>

<% else%>
<body background="../../imagenes/fondo_noticias.gif">
<table align="center" width="100%">
<tr>
<td width="33%" bgcolor="#FBE9A4"> <div align="center">
<p class="titulos">ADMINISTRADOR</p>
</div></td>
<td width="33%" bgcolor="#FBE9A4"> <div align="center">
<p class="titulos">CONVIVIR</p>
</div></td>

</tr>
<tr>
<td class="titulos" colspan="2" headers="30%"><div align="center" class="texto">
<p>&nbsp;</p>
<p> Los datos fueron ingresados satisfactoriamente</p>
</p>
</div></td>
</tr>
<tr>
</tr>
<tr>
</tr>

<tr>
<td width="444" class="texto"><div align="center" class="texto">

<a href="Agregarprensa.asp">Ingresar nueva prensa</a></div></td>
<td width="444" class="texto"><div align="center" class="texto"><a href="listadopre.asp"> ver listado</a></div></td>



</tr>
</table>
<% End If %>
  #4 (permalink)  
Antiguo 05/10/2007, 08:14
 
Fecha de Ingreso: octubre-2007
Ubicación: en santiago chile
Mensajes: 34
Antigüedad: 16 años, 6 meses
Puntos: 0
Re: formulario / enviar archivos adjuntos en html

loader.asp (ojo esta no se modifica)

<%
' -- Loader.asp --
' -- version 1.1

Class Loader
Private dict

Private Sub Class_Initialize
Set dict = Server.CreateObject("Scripting.Dictionary")
End Sub

Private Sub Class_Terminate
If IsObject(intDict) Then
intDict.RemoveAll
Set intDict = Nothing
End If
If IsObject(dict) Then
dict.RemoveAll
Set dict = Nothing
End If
End Sub

Public Property Get Count
Count = dict.Count
End Property

Public Sub Initialize
Dim binData
binData = Request.BinaryRead(Request.TotalBytes)
getData binData
End Sub

Public Function getFileData(name)
If dict.Exists(name) Then
getFileData = dict(name).Item("Value")
Else
getFileData = stringToByte("Not Found")
End If
End Function

Public Function getValue(name)
If dict.Exists(name) Then
getValue = dict(name).Item("Value")
Else
getValue = "Not Found"
End If
End Function

Public Function saveToFile(name, path)
If dict.Exists(name) Then
Dim temp
temp = dict(name).Item("Value")
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fso.CreateTextFile(path)
For tPoint = 1 to LenB(temp)
file.Write Chr(AscB(MidB(temp,tPoint,1)))
Next
file.Close
saveToFile = True
Else
saveToFile = False
End If
End Function

Public Function getFileName(name)
If dict.Exists(name) Then
Dim temp, tempPos
temp = dict(name).Item("FileName")
tempPos = 1 + InStrRev(temp, "\")
getFileName = Mid(temp, tempPos)
Else
getFileName = "Not Found"
End If
End Function

Public Function getFilePath(name)
If dict.Exists(name) Then
Dim temp, tempPos
temp = dict(name).Item("FileName")
tempPos = InStrRev(temp, "\")
getFilePath = Mid(temp, 1, tempPos)
Else
getFilePath = "Not Found"
End If
End Function

Public Function getFilePathComplete(name)
If dict.Exists(name) Then
getFilePathComplete = dict(name).Item("FileName")
Else
getFilePathComplete = "Not Found"
End If
End Function

Public Function getFileSize(name)
If dict.Exists(name) Then
getFileSize = LenB(dict(name).Item("Value"))
Else
getFileSize = "Not Found"
End If
End Function

Public Function getFileSizeTranslated(name)
If dict.Exists(name) Then
temp = 1 + LenB(dict(name).Item("Value"))
If Len(temp) <= 3 Then
getFileSizeTranslated = temp & " bytes"
ElseIf Len(temp) > 6 Then
temp = FormatNumber(((temp / 1024) / 1000), 2)
getFileSizeTranslated = temp & " megabytes"
Else
temp = FormatNumber((temp / 1024), 2)
getFileSizeTranslated = temp & " kilobytes"
End If
Else
getFileSize = "Not Found"
End If
End Function

Public Function getContentType(name)
If dict.Exists(name) Then
getContentType = dict(name).Item("ContentType")
Else
getContentType = "Not Found"
End If
End Function

Private Sub getData(rawData)
Dim separator
separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)

Dim lenSeparator
lenSeparator = LenB(separator)

Dim currentPos
currentPos = 1
Dim inStrByte
inStrByte = 1
Dim value, mValue
Dim tempValue
tempValue = ""

While inStrByte > 0
inStrByte = InStrB(currentPos, rawData, separator)
mValue = inStrByte - currentPos

If mValue > 1 Then
value = MidB(rawData, currentPos, mValue)

Dim begPos, endPos, midValue, nValue
Dim intDict
Set intDict = Server.CreateObject("Scripting.Dictionary")

begPos = 1 + InStrB(1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
nValue = endPos

Dim nameN
nameN = MidB(value, begPos, endPos - begPos)

Dim nameValue
If InStrB(1, value, stringToByte("Content-Type")) > 1 Then

begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))

midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "FileName", trim(byteToString(midValue))

begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
endPos = InStrB(begPos, value, ChrB(13))

midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "ContentType", trim(byteToString(midValue))

begPos = endPos + 4
endPos = LenB(value)

nameValue = MidB(value, begPos, endPos - begPos)
Else
nameValue = trim(byteToString(MidB(value, nValue + 2)))
End If

intDict.Add "Value", nameValue
intDict.Add "Name", nameN

dict.Add byteToString(nameN), intDict
End If

currentPos = lenSeparator + inStrByte
Wend
End Sub

End Class

Private Function stringToByte(toConv)
Dim tempChar
For i = 1 to Len(toConv)
tempChar = Mid(toConv, i, 1)
stringToByte = stringToByte & chrB(AscB(tempChar))
Next
End Function

Private Function byteToString(toConv)
For i = 1 to LenB(toConv)
byteToString = byteToString & chr(AscB(MidB(toConv,i,1)))
Next
End Function

%>

espero que te sirva, la unica que no debes modificar es el loader.asp, las otras puedes modificarlas
  #5 (permalink)  
Antiguo 06/10/2007, 06:14
Avatar de lrecchia  
Fecha de Ingreso: diciembre-2005
Mensajes: 214
Antigüedad: 18 años, 4 meses
Puntos: 2
Re: formulario / enviar archivos adjuntos en html

mil gracias¡¡¡¡¡
voy a probarlo....
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:39.