Ver Mensaje Individual
  #3 (permalink)  
Antiguo 02/10/2011, 13:26
Avatar de hackjose
hackjose
 
Fecha de Ingreso: abril-2010
Ubicación: Edo Mexico
Mensajes: 1.178
Antigüedad: 14 años
Puntos: 131
Respuesta: 4yuda con CURL

Mas info
Siento que este formulario con este script tiene algo muy importante que ver con el echo de que no se inserte el anuncio
Como tiene un evento onsubmit y como este no es llamado nunca pues siento que hay algo
//No he estudiado bien Javascript

Código HTML:
Ver original
  1. <script type="text/javascript">
  2. //<![CDATA[
  3. function enviar(frm){
  4.         //  Titulo
  5.         if (!stringHasMinimumSize(frm.titol.value,10))
  6.         {
  7.             frm.titol.focus();
  8.             return msgErr("El título ha de tener un mínimo de 10 carácteres");
  9.         }
  10.        if (!stringHasMinimumNumberOfLetters(frm.titol.value,5))
  11.        {
  12.             frm.titol.focus();
  13.             return msgErr('El titulo ha de tener como minimo 5 letras');
  14.         }
  15.         // Descripcion
  16.         if ( tinyMCE.get('descripcio').getContent().length < 30 )
  17.         {
  18.             return msgErr("La descripción del anuncio ha de tener un mínimo de 30 carácteres");
  19.         }
  20.         //  Codigo de seguridad
  21.         if (frm.security_code) {
  22.            if (frm.security_code.value.length == 0) {
  23.                 frm.security_code.focus();
  24.                return msgErr("Debe ingresar el código de seguridad.");
  25.            }
  26.         }
  27.  
  28.         error=0;
  29.  
  30.         if (frm.image !=undefined)
  31.         {
  32.             if (frm.image.value!='')
  33.             {
  34.                 ext=frm.image.value.substring(frm.image.value.length-4).toLowerCase();
  35.                 if((ext!='.jpg')&&(ext!='jpeg')&&(ext!='.gif')&&(ext!='.png'))
  36.                 {
  37.                     alert('Solo se permiten imágenes del tipo JPG, GIF o PNG');
  38.                     error=1;
  39.                 }
  40.             }
  41.         }
  42.  
  43.         if ((frm.image2 !=undefined)&&(error==0))
  44.         {
  45.             if (frm.image2.value!='')
  46.             {
  47.                 ext=frm.image2.value.substring(frm.image2.value.length-4).toLowerCase();
  48.  
  49.                 if((ext!='.jpg')&&(ext!='jpeg')&&(ext!='.gif')&&(ext!='.png'))
  50.                 {
  51.                     alert('Solo se permiten imágenes del tipo JPG, GIF o PNG');
  52.                     error=1;
  53.                 }
  54.             }
  55.         }
  56.        errorImgsMsg = '';
  57.        for (i=0; i < MAX_FILES + 1; i++) {
  58.            if (document.getElementById('desc_'+i+'_edited')) {
  59.                if (document.getElementById('desc_'+i+'_edited').value == 1) {
  60.                    data = document.getElementById('desc_'+i).value;
  61.                    if (Trim(data).length > 0) {
  62.                        if (!(data.length > 4 && data.length < 61)) {
  63.                            errorImgsMsg = 'La descripcion de la imagen '+ i +' debe tener entre 5 y 60 caracteres.';
  64.                            break;
  65.                        }
  66.                    }
  67.                }
  68.            }
  69.        }
  70.        if (errorImgsMsg != '') {
  71.            alert(errorImgsMsg);
  72.            error = 1;
  73.        }
  74.  
  75.         if ((frm.image2 !=undefined)&&(error==0))
  76.         {
  77.             if (frm.image2.value!='')
  78.             {
  79.                 ext=frm.image2.value.substring(frm.image2.value.length-4).toLowerCase();
  80.                 if((ext!='.jpg')&&(ext!='jpeg')&&(ext!='.gif')&&(ext!='.png'))
  81.                 {
  82.                     alert('Solo se permiten imágenes del tipo JPG, GIF o PNG');
  83.                     error=1;
  84.                 }
  85.             }
  86.         }
  87.        
  88.         //  Email:
  89.         if( frm.mail.value.length > 0 && ! validaEmail(frm.mail.value)  )
  90.         {
  91.             alert(JS_EMAIL_MAL_FORMADO);
  92.             frm.mail.focus()
  93.             return false;
  94.         }
  95.         else
  96.         {
  97.             frm.mail.value = checkeoDeDominio( frm.mail.value );
  98.         }
  99.  
  100.         if(error==0) {
  101.            // Si tengo seleccionada una provincia, entonces pongo en el action el urlbase de esa provincia, sino, la del pais
  102.            var drpPaises = window.document.getElementById('id_pais');
  103.            var drpProvincias = window.document.getElementById('id_prov');
  104.            if (drpProvincias.value != '0') {
  105.                frm.action = 'http://'+drpProvincias.options[drpProvincias.selectedIndex].getAttribute('ma_urlbase')+'/anunci_insert_run.php';
  106.            } else {
  107.                if (drpPaises.getAttribute('ma_urlbase')) {
  108.                    frm.action = 'http://'+drpPaises.getAttribute('ma_urlbase')+'/anunci_insert_run.php';
  109.                } else {
  110.                    frm.action = 'http://'+drpPaises.options[drpPaises.selectedIndex].getAttribute('ma_urlbase')+'/anunci_insert_run.php';
  111.                }
  112.            }
  113.             return true;
  114.        }
  115.  
  116.         return false;
  117.     }
  118.  
  119. //]]>
  120.  
  121.         <form action="/anunci_insert_run.php" name="form" class="form" method="post" enctype="multipart/form-data" onsubmit="if (!enviar(this)) { event.returnValue = false; event.cancelBubble = true; return false; }">
  122.         <p><input type="hidden" name="categoria" value="21" /></p>
  123.  
  124.         <p>
  125.             <label for="titol">Título:</label>
  126.             <input
  127.                type="text"
  128.                name="titol"
  129.                id="titol"
  130.                maxlength="128"
  131.                value=""
  132.                size="60" />
  133.         </p><p>
  134.             <label for='id_pais'>País:</label>
  135.             <select
  136.                name='id_pais'
  137.                id='id_pais'
  138.                onChange="actualiza_provincias(this.value, document.getElementById('sel_prov').value);"><option value="1" ma_urlbase="www.mundoanuncio.com" selected="selected">Todos</option>
  139. <option value='779268' ma_urlbase='www.mundoanuncio.com' >Afganistán</option>
  140. <option value='779300' ma_urlbase='www.mundoanuncio.com' >Egipto</option>
  141. <option value='779301' ma_urlbase='www.mundoanuncio.com' >Emiratos Árabes Unidos</option>
  142. <option value='779302' ma_urlbase='www.mundoanuncio.com' >Eritrea</option>
  143. <option value='779304' ma_urlbase='www.mundoanuncio.com' >Eslovenia</option>
  144. <option value='2' ma_urlbase='www.mundoanuncio.com' >España</option>
  145. <option value='13' ma_urlbase='www.mundoanuncio.com' >Estados Unidos</option>
  146. <option value='779305' ma_urlbase='www.mundoanuncio.com' >Estonia</option>
  147. <option value='779346' ma_urlbase='www.mundoanuncio.com' >Malasia</option>
  148. <option value='779347' ma_urlbase='www.mundoanuncio.com' >Malawi</option>
  149. <option value='779348' ma_urlbase='www.mundoanuncio.com' >Maldivas</option>
  150. <option value='779349' ma_urlbase='www.mundoanuncio.com' >Mali</option>
  151. <option value='779350' ma_urlbase='www.mundoanuncio.com' >Marianas del Norte</option>
  152. <option value='779424' ma_urlbase='www.mundoanuncio.com' >Zimbabwe</option>
  153.             </p><p>
  154.         <input type="hidden" id="sel_prov" name="sel_prov" value="0" />
  155.             <label for="id_prov">Provincia:</label>
  156.         <div id="prov_div"><select id="id_prov"></select></div>
  157.         </p>
  158.  
  159.         <p>
  160.             <label for="ciudad" class="optional" >Ciudad / Población (opcional):</label>
  161.             <input type="text" name="ciudad" id="ciudad" size="30" value="" />
  162.         </p>
  163.  
  164.         <p>
  165.             <label for="barrio" class="optional">Barrio (opcional):</label>
  166.             <input type="text" name="barrio" id="barrio" size="30" value="" />
  167.         </p>
  168.  
  169.  
  170.         <p class="descripcio">
  171.         <div class="tinymce">
  172.         <label style="display:block;" for="descripcio">Descripción:</label>
  173.         <textarea name="descripcio" id="descripcio" rows="15" cols="45"></textarea>
  174.         <script type="text/javascript">
  175.             tinyMCE.init({
  176.                 mode : "exact",
  177.                 elements : "descripcio",
  178.                 content_css : "/css/tinymce_content.css",
  179.                 theme : "advanced",
  180.                 width : "486",
  181.                 theme_advanced_buttons1 : "bold, italic, undo, redo, link, unlink",
  182.                 theme_advanced_buttons2 : "",
  183.                 theme_advanced_buttons3 : "",
  184.                 theme_advanced_toolbar_location : "top",
  185.                 theme_advanced_toolbar_align : "left"
  186.             });
  187.             </script>
  188.         </div>
  189.         </p>
  190.         <p><span class="label"></span><input type='radio' name='opcio_especial' id='opcio_especial0' value='7' checked='checked' /> <label for='opcio_especial0' class='radio'>Venta</label>
  191. <input type='radio' name='opcio_especial' id='opcio_especial1' value='8'  /> <label for='opcio_especial1' class='radio'>Compra</label>
  192. </p>
  193. <p>
  194.         <label for='mail' class='optional'>E-mail (opcional):</label>
  195.         <input size='30' type='text' name='mail' id='mail' value='' />
  196.         <input type='hidden' name='mail_visible' value='' />
  197. </p>
  198. <div id="img_div">  <input type="hidden" value="1" name="img_count" id="img_count" />  <input type="hidden" value="1" name="img_max_id" id="img_max_id" />  <div id="img_container">    <p id="img_p_tpl" style="display:none;">        <label for="image_tpl" class="optional" id="lbl_tpl">Foto: (opcional)</label>        <input type="file" name="image_tpl" id="image_tpl" onChange="new_img();" />        <input type="button" name="remove_tpl" id="remove_tpl" value="Eliminar" onClick="remove_img(this);" />        <br /><label for="desc_tpl" id="lbl_desc_tpl" style="display: none;">&nbsp;</label><input type="text" class="italicDesc" name="desc_tpl" id="desc_tpl" value="Descripci&oacute;n de la foto ..." onClick="cleanVal(this);" style="margin-left: 3px; display:none;" maxlength="60" size="30"/><input type="hidden" name="desc_tpl_edited" id="desc_tpl_edited" value="0" />    </p>    <p id="img_p_1" style="display:block;">        <label for="image_1" class="optional" id="lbl_1">Foto: (opcional)</label>        <input type="file" name="image_1" id="image_1" onChange="new_img();" />        <input type="button" name="remove_1" id="remove_1" value="Eliminar" onClick="remove_img(this);" style="margin-left: -3px;" />        <br /><label for="desc_1" id="lbl_desc_1" style="display: none;">&nbsp;</label><input type="text" class="italicDesc" name="desc_1" id="desc_1" value="Descripci&oacute;n de la foto ..." onClick="cleanVal(this);" style="margin-left: 3px; display:none;" maxlength="60" size="30"/><input type="hidden" name="desc_1_edited" id="desc_1_edited" value="0" />    </p>  </div><p class="notice">La imagen no puede ser mayor a 5 MB. El formato debe ser JPEG, GIF o PNG.</p></div>
  199.         <p>
  200.             <label for='preu' class='optional'>Precio (opcional):</label>
  201.             <input type='text' name='preu' id='preu' size='15' maxlength='32' />
  202.         </p>
  203.             <p class='buttons'>
  204.                 <input type='submit' value='Inserta anuncio' />
  205.                 </p>
  206. <script type="text/javascript">
  207. //<![CDATA[
  208. document.getElementById('titol').focus()
  209. //]]>
  210.     </form>