Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
876 connectés 

  FORUM HardWare.fr
  Programmation
  HTML/CSS

  Champ texte avec mise en forme

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Champ texte avec mise en forme

n°1201715
astik89
Posté le 18-09-2005 à 01:16:03  profilanswer
 

Je souhaite intégrer dans un formulaire un champ texte multiple pour que l'utilisateur puisse mettre en forme (gras, italique, couleur, lien) son texte, qui sera stocké dans une base MySQL et sera ensuite réinjecté dans un script php.
Comment faire ceci, ou où puis-je le trouver tout fait??
 
En gros je veux le meme principe que la page où on tape les messages dans HFR
 
Merci
Astik


Message édité par astik89 le 18-09-2005 à 15:54:18
mood
Publicité
Posté le 18-09-2005 à 01:16:03  profilanswer
 

n°1201759
sielfried
Posté le 18-09-2005 à 10:53:29  profilanswer
 

C'est du javascript, pas du PHP.
 
Et si tu fouilles un peu dans les sources du forum tu peux trouver facilement.


---------------
StarCraft Professional Gaming Database | [Ze Topic] Starcraft/BroodWar
n°1201793
dwogsi
Défaillance cérébrale...
Posté le 18-09-2005 à 12:58:58  profilanswer
 

Et je dirais même que que c'est dans "Windows, Software & Réseaux" que ca va ce genre de topic, mais bon...


---------------
-- Debian -- Le système d'exploitation universel | Le gras c'est la vie! | /(bb|[^b]{2})/
n°1201970
astik89
Posté le 18-09-2005 à 21:36:20  profilanswer
 

Merci, je n'avais pas pensé à regarder dans les sources HFR.
J'ai réussi à fiare ce que je voulais mais sa ne fonctionne que sous IE, sous firefox les balises ne sont pas insérées lorsqu'on clique dessus.
 

Code :
  1. <head>
  2. <script language="javascript" type="text/javascript">
  3. var style=new Array('g','/g','i','/i','s','/s','email','/email','lien=','/lien','img','/img','quote','/quote','fixed','/fixed','cpp','/cpp','url','/url');
  4. var stockage=new Array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
  5. lien="http://";
  6. function openChild(file,window) {
  7. childWindow=open(file,window,'width=800,height=600');
  8. if (childWindow.opener ==null) childWindow.opener=self;
  9. }
  10. function passfocus() {
  11. document.getElementById('passf').style.display=(document.all && !opera)?'block':'table-row';
  12. }
  13. function MM_findObj(n, d) { //v3.0
  14. var p,i,x;
  15. if(!d) d=document;
  16. if((p=n.indexOf("?" ))>0&&parent.frames.length) d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  17. if(!(x=d[n])&&d.all) x=d.all[n];
  18. for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
  19. for(i=0;!x&&d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
  20. }
  21. function storeCaret (textEl) {
  22. if (textEl.createTextRange) textEl.caretPos=document.selection.createRange().duplicate();
  23. }
  24. function insertAtCaret (textEl, text) {
  25. if (textEl.createTextRange && textEl.caretPos) {
  26.  var caretPos=textEl.caretPos;
  27.  caretPos.text=caretPos.text.charAt(caretPos.text.length - 1)==' ' ? text + ' ' : text;
  28. }
  29. }
  30. function insertInCaret (textEl, text, text2) {
  31. if (textEl.createTextRange && textEl.caretPos) {
  32.  var caretPos=textEl.caretPos;
  33.  selectedtext=caretPos.text;
  34.  caretPos.text= caretPos.text.charAt(caretPos.text.length - 1)=='' ? text + '' : text;
  35.  caretPos.text=caretPos.text + selectedtext + text2;
  36. }
  37. }
  38. function palette(id,vernav) {
  39. if (vernav>=4) {
  40.  MM_findObj('contenu').focus();
  41.  if (MM_findObj('contenu').createTextRange && MM_findObj('contenu').caretPos) {
  42.   var caretPos=MM_findObj('contenu').caretPos;
  43.   if (caretPos.text.length>0) {
  44.    if (id !=8)insertInCaret(MM_findObj('contenu'),"["+style[id]+"]","["+style[id+1]+"]" );
  45.    else {
  46.     geturl=prompt("veuillez entrer l'url",'http://');
  47.     insertInCaret(MM_findObj('contenu'),"["+style[id]+geturl+"]","["+style[id+1]+"]" );
  48.    }
  49.   } else {
  50.    if ( (countbalise('['+style[id],'contenu')+countbalise('['+style[id+1],'contenu'))%2 ==0) {
  51.     if (id !=8) insertAtCaret(MM_findObj('contenu'),"["+style[id]+"]" );
  52.     else {
  53.      geturl=prompt("veuillez entrer l'url",'http://');
  54.      insertAtCaret(MM_findObj('contenu'),"["+style[id]+geturl+"]" );
  55.     }
  56.    } else {
  57.     insertAtCaret(MM_findObj('contenu'),"["+style[id+1]+"]" );
  58.    }
  59.    MM_findObj('contenu').focus()
  60.   }
  61.  }
  62. } else {
  63.  if (stockage[id]=='0') {
  64.   var temp=document.hop.contenu.value;
  65.   document.hop.contenu.value=temp+' '+'['+style[id]+']';
  66.   stockage[id]='1';
  67.  } else {
  68.   var temp=document.hop.contenu.value;
  69.   document.hop.contenu.value=temp+'['+style[id+1]+']'+' ';
  70.   stockage[id]='0';
  71.  }
  72. }
  73. }
  74. function countbalise(b,ch) {
  75. count=0;
  76. pos=MM_findObj(ch).value.indexOf(b);
  77. while ( pos !=-1 ){
  78.  count++;
  79.  pos=MM_findObj(ch).value.indexOf(b,pos+1);
  80. }
  81. return count;
  82. }
  83. function insertElt(MyString,vernav) {
  84. if (vernav>=4) {
  85.  MM_findObj('contenu').focus();
  86.  if ((MM_findObj('contenu').createTextRange) && (MM_findObj('contenu').caretPos)) {
  87.   var caretPos=MM_findObj('contenu').caretPos;
  88.   if (caretPos.text.length>0) insertInCaret(MM_findObj('contenu'),MyString,"" );
  89.   else insertAtCaret(MM_findObj('contenu'),MyString);
  90.  }
  91. } else {
  92.  var temp=document.hop.contenu.value;
  93.  document.hop.contenu.value=temp+MyString;
  94. }
  95. }
  96. function insertTag(MyString,vernav) {
  97. if (vernav>=4) {
  98.  MM_findObj('contenu').focus();
  99.  if (MM_findObj('contenu').createTextRange && MM_findObj('contenu').caretPos) {
  100.   var caretPos=MM_findObj('contenu').caretPos;
  101.   if (caretPos.text.length>0) insertInCaret(MM_findObj('contenu'),"["+MyString+"]","[/"+MyString+"]" );
  102.   else {
  103.    if ( (countbalise('['+MyString,'contenu')+countbalise('[/'+MyString,'contenu'))%2 ==0) insertAtCaret(MM_findObj('contenu'),"["+MyString+"]" );
  104.    else insertAtCaret(MM_findObj('contenu'),"[/"+MyString+"]" );
  105.    MM_findObj('contenu').focus();
  106.   }
  107.  }
  108. } else {
  109.  if (stockage[12]=='0') {
  110.   var temp=document.hop.contenu.value;
  111.   document.hop.contenu.value=temp+' '+'['+MyString+']';
  112.   stockage[12]='1';
  113.  } else {
  114.   var temp=document.hop.contenu.value;
  115.   document.hop.contenu.value=temp+'[/'+MyString+']'+' ';
  116.   stockage[12]='0';
  117.  }
  118. }
  119. ///Color
  120. col0=new Array(255,255,0,255,0,0);
  121. col1=new Array(255,0,255,255,0,0);
  122. col2=new Array(0,0,255,0,0,255);
  123. col3=new Array(0,255,0,0,255,0);
  124. var base_hexa="0123456789ABCDEF";
  125. function dec2Hexa(number) {
  126. return base_hexa.charAt(Math.floor(number / 16)) + base_hexa.charAt(number % 16);
  127. }
  128. function RGB2Hexa(TR,TG,TB) {
  129. return "#" + dec2Hexa(TR) + dec2Hexa(TG) + dec2Hexa(TB);
  130. }
  131. function lightCase(MyObject) {
  132. document.getElementById('ColorUsed').bgColor=document.getElementById(MyObject).bgColor;
  133. document.getElementById('ColorUsedMem').value=document.getElementById(MyObject).bgColor;
  134. }
  135. function highlightCase(MyObject) {
  136. document.getElementById('ColorUsed').bgColor=document.getElementById(MyObject).bgColor;
  137. }
  138. function backlightCase(MyObject) {
  139. document.getElementById('ColorUsed').bgColor=document.getElementById('ColorUsedMem').value;
  140. }
  141. function rgb(dm,ta,index,img,explication) {
  142. fm=dm + 18;
  143. for (i=dm;i<fm+1;i++) {
  144.  r=Math.floor(ta[0] + (i-dm)*(ta[1]-ta[0])/(fm-dm));
  145.  g=Math.floor(ta[2] + (i-dm)*(ta[3]-ta[2])/(fm-dm));
  146.  b=Math.floor(ta[4] + (i-dm)*(ta[5]-ta[4])/(fm-dm));
  147.  codehex=dec2Hexa(r) + '' + dec2Hexa(g) + '' + dec2Hexa(b);
  148.  document.write('<td style="cursor:pointer" onclick="TAinsert(\'[\'+document.getElementById(\'tableId'+index+'\').bgColor+\']\',\'[/\'+document.getElementById(\'tableId'+index+'\').bgColor+\']\');lightCase(\'tableId'+index+'\');\" onmouseover=\"highlightCase(\'tableId'+index+'\');" onmouseout="backlightCase();" id="tableId'+index+'" bgcolor="'+RGB2Hexa(r,g,b)+'" width="3" height="17"><img title="'+explication+' : [#'+codehex+']text[/#'+codehex+']" src="'+img+'" alt="" width="3" height="17" /></td>\n');
  149.  index++;
  150. }
  151. }
  152. function rgb2(rte,dm,ta,index,img,explication) {
  153. fm=dm + 18;
  154. for (i=dm;i<fm+1;i++) {
  155.  r=Math.floor(ta[0] + (i-dm)*(ta[1]-ta[0])/(fm-dm));
  156.  g=Math.floor(ta[2] + (i-dm)*(ta[3]-ta[2])/(fm-dm));
  157.  b=Math.floor(ta[4] + (i-dm)*(ta[5]-ta[4])/(fm-dm));
  158.  codehex=dec2Hexa(r) + '' + dec2Hexa(g) + '' + dec2Hexa(b);
  159.  document.write('<td style="cursor:pointer" onclick="FormatText(\''+rte+'\',\'forecolor\',document.getElementById(\'tableId'+index+'\').bgColor);lightCase(\'tableId'+index+'\');" onmouseover=\"highlightCase(\'tableId'+index+'\');" onmouseout="backlightCase();" id="tableId'+index+'" bgcolor="' + RGB2Hexa(r,g,b) + '" width="2" height="15"><img title="'+explication+'" src="'+img+'" alt="" width="2" height="15" /></td>\n');
  160.  index++;
  161. }
  162. }
  163. /************************************************************/
  164. /* freekill (freekill.free.fr)      */
  165. /************************************************************/
  166. function countInstances(open,closed) {
  167. var opening=document.hop.contenu.value.split(open);
  168. var closing=document.hop.contenu.value.split(closed);
  169. return opening.length + closing.length - 2;
  170. }
  171. function TAinsert(text1,text2) {
  172. var ta=document.getElementById('contenu');
  173. if (document.selection) {
  174.  var str=document.selection.createRange().text;
  175.  ta.focus();
  176.  var sel=document.selection.createRange();
  177.  if (text2!="" ) {
  178.   if (str=="" ) {
  179.    var instances=countInstances(text1,text2);
  180.    if (instances%2 !=0) sel.text=sel.text + text2;
  181.    else sel.text=sel.text + text1;
  182.   } else sel.text=text1 + sel.text + text2;
  183.  } else sel.text=sel.text + text1;
  184. } else if (ta.selectionStart || ta.selectionStart ==0) {
  185.  if (ta.selectionEnd > ta.value.length) ta.selectionEnd=ta.value.length;
  186.  var firstPos=ta.selectionStart;
  187.  var secondPos=ta.selectionEnd+text1.length;
  188.  var contenuScrollTop=ta.scrollTop;
  189.  ta.value=ta.value.slice(0,firstPos)+text1+ta.value.slice(firstPos);
  190.  ta.value=ta.value.slice(0,secondPos)+text2+ta.value.slice(secondPos);
  191.  ta.selectionStart=firstPos+text1.length;
  192.  ta.selectionEnd=secondPos;
  193.  ta.focus();
  194.  ta.scrollTop=contenuScrollTop;
  195. } else { // Opera
  196.  var sel=document.hop.contenu;
  197.  var instances=countInstances(text1,text2);
  198.  if (instances%2 !=0 && text2 !="" ) sel.value=sel.value + text2;
  199.  else sel.value=sel.value + text1;
  200. }
  201. }
  202. </script></head>
  203. <body>
  204. <form name="Ajouter" method="POST" action="actu/admin.php">
  205. <table border="0" cellspacing="0">
  206.   <tr>
  207.     <td>
  208.   <LABEL><u>Texte:</u></LABEL>
  209.  </td>
  210.  <td width="50px">
  211.  </td>
  212.  <td>
  213.   <img style="cursor:pointer" class="text_bold" onclick="TAinsert('','');" title="Mettre en gras le texte. Syntaxe : texte" alt="[b]" src="/admin/images/bold.gif" width="27" height="28" />
  214.  </td>
  215.  <td>
  216.   <img style="cursor:pointer" onclick="TAinsert('[i]','');" title="Mettre en italique le texte. Syntaxe : texte" alt="[i]" src="/admin/images/italic.gif" width="25" height="28" />
  217.  </td>
  218.  <td>
  219.   <img style="cursor:pointer" onclick="TAinsert('','');" title="Souligner le texte. Syntaxe : texte" alt="[u]" src="/admin/images/underline.gif" width="26" height="28" />
  220.  </td>
  221.  <td>
  222.   <img style="cursor:pointer" onclick="TAinsert('http://adresse.du.site.com;','');" title="Insérer une URL. Syntaxe : texte" alt="[url]" src="/admin/images/url.gif" width="26" height="28" />
  223.  </td>
  224.  <td width="50px">
  225.  </td>
  226.     <td width="270px">
  227.   <table class="none" style="margin-top:6px; border:0px" cellspacing="0" cellpadding="0">
  228.    <tr>
  229.     <td style="cursor:pointer; width:15px; border:1px solid #000000" id="ColorUsed" title="Dernière couleur sélectionnée"><img src="/admin/images/trans.gif" alt="" width="15" height="17" onclick="TAinsert('['+document.getElementById('ColorUsed').bgColor+']','[/'+document.getElementById('ColorUsed').bgColor+']');" /><input type="hidden" value="" name="ColorUsedMem" id="ColorUsedMem" /></td>
  230.     <td width="5">&nbsp;
  231.      <script language="JavaScript" type="text/javascript">
  232.       <!--
  233.       rgb(0,col0,0,'/admin/images/trans.gif','Mettre du texte en couleur');
  234.       rgb(18,col1,50,'/admin/images/trans.gif','Mettre du texte en couleur');
  235.       rgb(36,col2,100,'/admin/images/trans.gif','Mettre du texte en couleur');
  236.       rgb(0,col3,150,'/admin/images/trans.gif','Mettre du texte en couleur');
  237.       // -->
  238.      </script>
  239.     </td>
  240.    </tr>
  241.   </table>
  242.  </td>
  243.   </tr>
  244. </table>
  245.     <p><textarea name="contenu" cols="100" rows="3" accessKey="c"></textarea>
  246.     <p>
  247.       <input type="submit" name="Action" value="Ajouter">
  248.       <input name="Action" type="reset" id="Action" value="Effacer les données">
  249.       <input name="Action" type="submit" id="Action" value="Retour">
  250.     </p>
  251. </form>
  252. </body>


Message édité par astik89 le 18-09-2005 à 21:36:43
n°1202791
astik89
Posté le 19-09-2005 à 21:16:34  profilanswer
 

:bounce:  :bounce:

n°1203598
dwogsi
Défaillance cérébrale...
Posté le 20-09-2005 à 16:47:10  profilanswer
 

La franchement j'ais pas le courage de regarder tout le code...  :o


---------------
-- Debian -- Le système d'exploitation universel | Le gras c'est la vie! | /(bb|[^b]{2})/
n°1203604
skeye
Posté le 20-09-2005 à 16:51:12  profilanswer
 

Sous FF la console javascript dit quoi?:o


---------------
Can't buy what I want because it's free -
n°1203648
gatsusat
Posté le 20-09-2005 à 17:28:09  profilanswer
 

ya du code de merde de droite et de gauche ca vaut rien ton JS là

n°1203747
astik89
Posté le 20-09-2005 à 18:53:09  profilanswer
 

skeye a écrit :

Sous FF la console javascript dit quoi?:o


Citation :

Erreur : ta has no properties
Fichier Source : http://admin.artdeladentelleenbour [...] jouter.php
Ligne : 245

n°1204730
astik89
Posté le 21-09-2005 à 21:09:56  profilanswer
 

:bounce:


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  HTML/CSS

  Champ texte avec mise en forme

 

Sujets relatifs
Au sujet du texte visible d'une pageProbleme de requete et de texte en php [Résolu, euh en fait non]
pb image et texteCréer un champ de saisie formulaire dans une page web (newbie) ?
Remplcer un lien texte par une imageChamp non modifiable
pb mise en page CSSRécupérer le type d'un champ
Concaténation de fichiers texteRetour à la ligne sous IE qui sabote la mise en page.
Plus de sujets relatifs à : Champ texte avec mise en forme


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR