Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

maurohpg

RichText Editor

Recommended Posts

Olá, estou tenatando fazer funcionar o RichTExt Editor....consegui configura-lo tudu certo. só estou com dificuldades em gravar as informações no BD, meu codigo é o seguinte:

 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="../Connections/conn_zell.asp" --><%'*** File Upload to: imgs_noticias, Extensions: "GIF,JPG,JPEG,BMP,PNG", Form: form1, Redirect: ""'*** Pure ASP File Upload -----------------------------------------------------' Copyright 2000 (c) George Petrov'' Script partially based on code from Philippe Collignon '              (http://www.asptoday.com/articles/20000316.htm)'' New features from GP:'  * Fast file save with ADO 2.5 stream object'  * new wrapper functions, extra error checking'  * UltraDev Server Behavior extension'' Version: 1.5.0'------------------------------------------------------------------------------Sub BuildUploadRequest(RequestBin)  'Get the boundary  PosBeg = 1  PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))  if PosEnd = 0 then    Response.Write "<b>Form was submitted with no ENCTYPE=""multipart/form-data""</b><br>"    Response.Write "Please correct the form attributes and try again."    Response.End  end if  boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)  boundaryPos = InstrB(1,RequestBin,boundary)  'Get all data inside the boundaries  Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))    'Members variable of objects are put in a dictionary object    Dim UploadControl    Set UploadControl = CreateObject("Scripting.Dictionary")    'Get an object name    Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))    Pos = InstrB(Pos,RequestBin,getByteString("name="))    PosBeg = Pos+6    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))    Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))    PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))    PosBound = InstrB(PosEnd,RequestBin,boundary)    'Test if object is of file type    If  PosFile<>0 AND (PosFile<PosBound) Then      'Get Filename, content-type and content of file      PosBeg = PosFile + 10      PosEnd =  InstrB(PosBeg,RequestBin,getByteString(chr(34)))      FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))      FileName = Mid(FileName,InStrRev(FileName,"\")+1)      'Add filename to dictionary object      UploadControl.Add "FileName", FileName      Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))      PosBeg = Pos+14      PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))      'Add content-type to dictionary object      ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))      UploadControl.Add "ContentType",ContentType      'Get content of object      PosBeg = PosEnd+4      PosEnd = InstrB(PosBeg,RequestBin,boundary)-2      Value = FileName      ValueBeg = PosBeg-1      ValueLen = PosEnd-Posbeg    Else      'Get content of object      Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))      PosBeg = Pos+4      PosEnd = InstrB(PosBeg,RequestBin,boundary)-2      Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))      ValueBeg = 0      ValueEnd = 0    End If    'Add content to dictionary object    UploadControl.Add "Value" , Value	    UploadControl.Add "ValueBeg" , ValueBeg    UploadControl.Add "ValueLen" , ValueLen	    'Add dictionary object to main dictionary    UploadRequest.Add name, UploadControl	    'Loop to next object    BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)  LoopEnd Sub'String to byte string conversionFunction getByteString(StringStr)  For i = 1 to Len(StringStr)    char = Mid(StringStr,i,1)   getByteString = getByteString & chrB(AscB(char))  NextEnd Function'Byte string to string conversionFunction getString(StringBin)  getString =""  For intCount = 1 to LenB(StringBin)   getString = getString & chr(AscB(MidB(StringBin,intCount,1)))   NextEnd FunctionFunction UploadFormRequest(name)  on error resume next  if UploadRequest.Item(name) then    UploadFormRequest = UploadRequest.Item(name).Item("Value")  end if  End Function'Process the uploadUploadQueryString = Replace(Request.QueryString,"GP_upload=true","")if mid(UploadQueryString,1,1) = "&" then	UploadQueryString = Mid(UploadQueryString,2)end ifGP_uploadAction = CStr(Request.ServerVariables("URL")) & "?GP_upload=true"If (Request.QueryString <> "") Then    if UploadQueryString <> "" then   GP_uploadAction = GP_uploadAction & "&" & UploadQueryString  end if End IfIf (CStr(Request.QueryString("GP_upload")) <> "") Then  GP_redirectPage = ""  If (GP_redirectPage = "") Then    GP_redirectPage = CStr(Request.ServerVariables("URL"))  end if      RequestBin = Request.BinaryRead(Request.TotalBytes)  Dim UploadRequest  Set UploadRequest = CreateObject("Scripting.Dictionary")    BuildUploadRequest RequestBin    GP_keys = UploadRequest.Keys  for GP_i = 0 to UploadRequest.Count - 1    GP_curKey = GP_keys(GP_i)    'Save all uploaded files    if UploadRequest.Item(GP_curKey).Item("FileName") <> "" then      GP_value = UploadRequest.Item(GP_curKey).Item("Value")      GP_valueBeg = UploadRequest.Item(GP_curKey).Item("ValueBeg")      GP_valueLen = UploadRequest.Item(GP_curKey).Item("ValueLen")      if GP_valueLen = 0 then        Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"        Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "<br>"        Response.Write "File does not exists or is empty.<br>"        Response.Write "Please correct and <A HREF=""javascript:history.back(1)"">try again</a>"      response.End     end if            'Create a Stream instance      Dim GP_strm1, GP_strm2      Set GP_strm1 = Server.CreateObject("ADODB.Stream")      Set GP_strm2 = Server.CreateObject("ADODB.Stream")            'Open the stream      GP_strm1.Open      GP_strm1.Type = 1 'Binary      GP_strm2.Open      GP_strm2.Type = 1 'Binary              GP_strm1.Write RequestBin      GP_strm1.Position = GP_ValueBeg      GP_strm1.CopyTo GP_strm2,GP_ValueLen          'Create and Write to a File      GP_curPath = Request.ServerVariables("PATH_INFO")      GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath,"/")) & "imgs_noticias")      if Mid(GP_curPath,Len(GP_curPath),1) <> "/" then        GP_curPath = GP_curPath & "/"      end if        on error resume next      GP_strm2.SaveToFile Trim(Server.mappath(GP_curPath))& "\" & UploadRequest.Item(GP_curKey).Item("FileName"),2      if err then        Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"        Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "<br>"        Response.Write "Maybe the destination directory does not exist, or you don't have write permission.<br>"        Response.Write "Please correct and <A HREF=""javascript:history.back(1)"">try again</a>"      err.clear      response.End     end if    end if  next    '*** GP NO REDIRECTend if  if UploadQueryString <> "" then  UploadQueryString = UploadQueryString & "&GP_upload=true"else    UploadQueryString = "GP_upload=true"end if  %><%' *** Edit Operations: (Modified for File Upload) declare variablesMM_editAction = CStr(Request.ServerVariables("URL")) 'MM_editAction = CStr(Request("URL"))If (UploadQueryString <> "") Then  MM_editAction = MM_editAction & "?" & UploadQueryStringEnd If' boolean to abort record editMM_abortEdit = false' query string to executeMM_editQuery = ""%><%' *** Edit Operations: (Modified for File Upload) declare variablesDim MM_editActionDim MM_abortEditDim MM_editQueryDim MM_editCmdDim MM_editConnectionDim MM_editTableDim MM_editRedirectUrlDim MM_editColumnDim MM_recordIdDim MM_fieldsStrDim MM_columnsStrDim MM_fieldsDim MM_columnsDim MM_typeArrayDim MM_formValDim MM_delimDim MM_altValDim MM_emptyValDim MM_iMM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))If (UploadQueryString <> "") Then  MM_editAction = MM_editAction & "?" & UploadQueryStringEnd If' boolean to abort record editMM_abortEdit = false' query string to executeMM_editQuery = ""%><%' *** Insert Record: (Modified for File Upload) set variablesIf (CStr(UploadFormRequest("MM_insert")) = "form1") Then  MM_editConnection = MM_conn_zell_STRING  MM_editTable = "Noticias"  MM_editRedirectUrl = "noticias_inserir_ok.asp"  MM_fieldsStr  = "titulo|value|texto|value|foto1|value|publicada|value"  MM_columnsStr = "titulo|',none,''|texto|',none,''|foto1|',none,''|publicado|none,1,0"  ' create the MM_fields and MM_columns arrays  MM_fields = Split(MM_fieldsStr, "|")  MM_columns = Split(MM_columnsStr, "|")    ' set the form values  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2    MM_fields(MM_i+1) = CStr(UploadFormRequest(MM_fields(MM_i)))  Next  ' append the query string to the redirect URL  If (MM_editRedirectUrl <> "" And UploadQueryString <> "") Then    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then      MM_editRedirectUrl = MM_editRedirectUrl & "?" & UploadQueryString    Else      MM_editRedirectUrl = MM_editRedirectUrl & "&" & UploadQueryString    End If  End IfEnd If%><%' *** Insert Record: (Modified for File Upload) construct a sql insert statement and execute itDim MM_tableValuesDim MM_dbValuesIf (CStr(UploadFormRequest("MM_insert")) <> "") Then  ' create the sql insert statement  MM_tableValues = ""  MM_dbValues = ""  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2    MM_formVal = MM_fields(MM_i+1)    MM_typeArray = Split(MM_columns(MM_i+1),",")    MM_delim = MM_typeArray(0)    If (MM_delim = "none") Then MM_delim = ""    MM_altVal = MM_typeArray(1)    If (MM_altVal = "none") Then MM_altVal = ""    MM_emptyVal = MM_typeArray(2)    If (MM_emptyVal = "none") Then MM_emptyVal = ""    If (MM_formVal = "") Then      MM_formVal = MM_emptyVal    Else      If (MM_altVal <> "") Then        MM_formVal = MM_altVal      ElseIf (MM_delim = "'") Then  ' escape quotes        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"      Else        MM_formVal = MM_delim + MM_formVal + MM_delim      End If    End If    If (MM_i <> LBound(MM_fields)) Then      MM_tableValues = MM_tableValues & ","      MM_dbValues = MM_dbValues & ","    End If    MM_tableValues = MM_tableValues & MM_columns(MM_i)    MM_dbValues = MM_dbValues & MM_formVal  Next  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"  If (Not MM_abortEdit) Then    ' execute the insert    Set MM_editCmd = Server.CreateObject("ADODB.Command")    MM_editCmd.ActiveConnection = MM_editConnection    MM_editCmd.CommandText = MM_editQuery    MM_editCmd.Execute    MM_editCmd.ActiveConnection.Close    If (MM_editRedirectUrl <> "") Then      Response.Redirect(MM_editRedirectUrl)    End If  End IfEnd If%><html><head><title>Mesquita - Administrador</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><script LANGUAGE="JavaScript">function getFileExtension(filePath) { //v1.0  fileName = ((filePath.indexOf('/') > -1) ? filePath.substring(filePath.lastIndexOf('/')+1,filePath.length) : filePath.substring(filePath.lastIndexOf('\\')+1,filePath.length));  return fileName.substring(fileName.lastIndexOf('.')+1,fileName.length);}function checkFileUpload(form,extensions) { //v1.0  document.MM_returnValue = true;  if (extensions && extensions != '') {    for (var i = 0; i<form.elements.length; i++) {      field = form.elements[i];      if (field.type.toUpperCase() != 'FILE') continue;      if (field.value == '') {        alert('File is required!');        document.MM_returnValue = false;field.focus();break;      }      if (extensions.toUpperCase().indexOf(getFileExtension(field.value).toUpperCase()) == -1) {        alert('This file is not allowed for uploading!');        document.MM_returnValue = false;field.focus();break;  } } }}</SCRIPT><script language="JavaScript" event="onscriptletevent(texto, eventData)" for="richedit">if (texto == "post") {form1.texto.value = richedit.doctexto;form1.submit();}</script><script language="JavaScript" type="text/javascript">function submitForm() {//make sure hidden and iframe values are in sync before submitting formupdateRTE('richedit'); //use this when syncing only 1 rich text editor ("rtel" is name of editor)//updateRTEs(); //uncomment and call this line instead if there are multiple rich text editors inside the formalert("Submitted value: "+document.form1.richedit.value) //alert submitted valuereturn true; //Set to false to disable form submission, for easy debugging.}</script></head><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1" onsubmit="return submitForm();" enctype="multipart/form-data" >  <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#0099FF">    <tr>       <td height="19"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>           inserir notícia         <% If request.QueryString("action") = "ok" Then %>        <font size="3">Notícia inserida com sucesso.</font>         <% end if %>        <% If request.QueryString("action") = "" Then %>        </strong></font></td>    </tr>  </table>  <table width="100%" border="0" cellspacing="2" cellpadding="0">    <tr>       <td height="121" bgcolor="#F3F3F3">         <table width="100%" border="0" cellspacing="2" cellpadding="0">          <tr>             <td width="10%"><font size="1" face="Arial, Helvetica, sans-serif">Título:</font></td>            <td width="90%"><font size="2" face="Arial, Helvetica, sans-serif">               <input name="titulo" type="text" id="titulo" style="border-color: #87898C; border-width: 1; background-color: #ffffff; border-style: solid; font-size: 10; font-family: arial;" size="50">              </font></td>          </tr>          <tr>             <td><font size="1" face="Arial, Helvetica, sans-serif">Foto:</font></td>            <td><font size="2" face="Arial, Helvetica, sans-serif">               <input name="foto1" type="file" id="foto1" style="border-color: #87898C; border-width: 1; background-color: #ffffff; border-style: solid; font-size: 10; font-family: arial;" size="32">              </font></td>          </tr>          <tr>             <td><font size="1" face="Arial, Helvetica, sans-serif">Publicada:</font></td>            <td><font size="2" face="Arial, Helvetica, sans-serif">               <input name="publicada" type="checkbox" id="publicada" value="Yes">              </font></td>          </tr>          <tr>             <td><font size="1" face="Arial, Helvetica, sans-serif">Notícia:</font></td>            <td> </td>          </tr>          <tr>             <td colspan="2"><div align="center"><font color="#CCCCCC" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Pressione                 "POST" para inserir a notícia </strong></font><font size="2" face="Arial, Helvetica, sans-serif"><br>                <textarea name="texto" id="textarea2" style="display: none"></textarea>                <br>                <object id="richedit" style="BACKGROUND-COLOR: buttonface" data="rte/richedit.html"width="750" height="350" type="text/x-scriptlet">                </object>                <br>               </font></div></td>           </tr>         </table>      <br>        <input type="hidden" name="MM_insert" value="form1">        <% end if %>      </td>  </tr></table>      </form></body></html>

Como eu devo fazer para gravar as informações para o BD????

Compartilhar este post


Link para o post
Compartilhar em outros sites

Galera seguinte eu só preciso saber como puxar as info que eu digito no editor e joga-lás no BD, não sei a função qeu eu coloco pra puxar as informações do editor.

 

estou usando as seguintes funções:

<script LANGUAGE="JavaScript">

function getFileExtension(filePath) { //v1.0

fileName = ((filePath.indexOf('/') > -1) ? filePath.substring(filePath.lastIndexOf('/')+1,filePath.length) : filePath.substring(filePath.lastIndexOf('\\')+1,filePath.length));

return fileName.substring(fileName.lastIndexOf('.')+1,fileName.length);

}

 

function checkFileUpload(form,extensions) { //v1.0

document.MM_returnValue = true;

if (extensions && extensions != '') {

for (var i = 0; i<form.elements.length; i++) {

field = form.elements;

if (field.type.toUpperCase() != 'FILE') continue;

if (field.value == '') {

alert('File is required!');

document.MM_returnValue = false;field.focus();break;

}

if (extensions.toUpperCase().indexOf(getFileExtension(field.value).toUpperCase()) == -1) {

alert('This file is not allowed for uploading!');

document.MM_returnValue = false;field.focus();break;

} } }

}

</SCRIPT>

<script language="JavaScript" event="onload" for="richedit">

richedit.options="history=yes;source=yes;dragdrop=yes;styleBar=yes;style=no;font=yes;fontSize

=yes;colour=yes;";

richedit.docHtml = form1.texto.innerText;

</script>

<script language="JavaScript" event="onscriptletevent(texto, eventData)" for="richedit">

if (texto == "post") {

form1.texto.value = richedit.doctexto;

form1.submit();

}

</script>

<script LANGUAGE="JavaScript">

function PegarTexto(f) {

f.elements.texto.value = document.all.richedit.html + "";

}

function Limpar() {

document.all.richedit.html = "";

}

</SCRIPT>

 

<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1" onSubmit="PegarTexto(this);;checkFileUpload(this,'');return document.MM_returnValue" enctype="multipart/form-data">

 

Uma função dessas são um paga pegar o botão do editor post fnciuonar ao invès de ter ki enviar pelo botão heim html.

A outra seria pra pegar as informações do form. e jogar no bd.

Compartilhar este post


Link para o post
Compartilhar em outros sites

To ligado que el usa um textarea para poder gravar no BD, mais só não sei como pegar as informações do editor html passar para o textarea e depois grava-las no BD, andei entrando no sites dos autores dos editores mais nem exemplo eles tem!!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Explore, é o seguinte eu tenho um textarea no visible que chama-se texto. Tenho um editor html Rich Text que está definido como richedit, tenho que pegar o html que e editor gerar e jogar para o textarea, e depois gravar no BD. estou usando o seguinte codigo para puxar do editor para o textarea, com isso grava no BD! <script LANGUAGE="JavaScript"> function PegarTexto(f) { f.elements.texto.value = document.all.richedit.html + ""; } function Limpar() { document.all.richedit.html = ""; }</SCRIPT>E no action do form: onSubmit="PegarTexto(this);

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara agora entendi!!!!!A unica forma que vi isso cara foi em PHP!!Mais talvez posso te ajudar naum sei.Como está seu textarea, pelo que sei ele deve ter o NAME e dentro do textarea deve ter o parametro! {$umBody|escape:"html"}tipo assim:<textarea cols=50 rows=15 name=body>{$umBody|escape:"html"}</textarea>Pelo que vi sua função esta certa!!!!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Assim, mais a funçãoq ue deveria puxar as infor do textarea, se eu deixo ele visivel logo qdo eu clico em enviar aparece undefined dentro do textarea e ele grava somente undefined no BD<textarea name="texto" style="display: none"></textarea>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom depois de 3 dias de tentativa eu resolvi o problema..coisa simples. tirei o botao submit que estava no form e usei o botão POST do próprio editor. e fiz ele puxar as informações com o seguinte cód.<script language="JavaScript" event="onscriptletevent(richedit, eventData)" for="richedit">if (richedit == "post") {form1.texto.value = eventData;form1.xhtml.value = richedit.docXHtml;form1.submit();}</script>variaveis richedit-nome do editor de textostexto-nometextareaxhtml-nometextareaSimples mais demorou heim!!!valeu a todos que me deram uma força!!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom....consegui recuperar o que está no editor html para o textarea e gravar no BD, mais agora to apanhando para para buscar do textarea para o editor, para que eu posso editar a noticia!recuperei a noticia com o seguinte cod.:<script LANGUAGE="JavaScript"> function PegarTexto(f) { f.elements.texto.value = document.all.richedit.html + ""; } function Limpar() { document.all.richedit.html = ""; }</SCRIPT>e no action dei um onSubmit="PegarTexto(this);"será que para recuperar para o editor eu teria que dar um onload no body???

Compartilhar este post


Link para o post
Compartilhar em outros sites

Errado caraé assim:<body onload="form1.PegarTexto.body.focus()">você coloco onde ia ficar o objeto BODY!PegarTexto é o nome da sua função certo??entaum é ela memo que deve ser la!

Compartilhar este post


Link para o post
Compartilhar em outros sites

minha função é essa<script LANGUAGE="JavaScript"> function PegarTexto(f) { f.elements.texto.value = document.all.richedit.html + ""; } function Limpar() { document.all.richedit.html = ""; }</SCRIPT>coloquei no body o que você havia me dito acima e deu erro.'form1.PegarTexto.body'é nulo ou não é um objetonão estou entendendo como pegar o html do textarea..do editor foi mais dificil e deu certinho pegar de uma text area para o editor não deve ser difificl!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.