Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Capturar valores checkbox y envialos por Email

Estas en el tema de Capturar valores checkbox y envialos por Email en el foro de Frameworks JS en Foros del Web. Hola necesito ayuda con este codigo, los checkbox no envian los valores, no tengo mucho conocimiento de AJAX. En el codigo PHP no veo problema ...
  #1 (permalink)  
Antiguo 02/09/2010, 08:59
 
Fecha de Ingreso: septiembre-2010
Mensajes: 3
Antigüedad: 13 años, 7 meses
Puntos: 0
Capturar valores checkbox y envialos por Email

Hola necesito ayuda con este codigo, los checkbox no envian los valores, no tengo mucho conocimiento de AJAX.
En el codigo PHP no veo problema alguno yo creo que es en Ayax.


Alguna Ayuda?


Código Javascript:
Ver original
  1. function valores(f) {
  2.         cual1 = 'checkbox[]';
  3.         todos = new Array();
  4.         for (var i = 0, total = f[cual1].length; i < total; i++) {
  5.                if (f[cual1][i].checked) todos[todos.length] = f[cual1][i].value;
  6.         }
  7.         document.getElementById('sel').value = todos.join(', ');
  8.         }

Código HTML:
Ver original
  1. <form action="form_submit_ast.php" id="ContactForm" name="ContactForm" method="post">
  2.       <div class="contentcontact_left">
  3.       <label>Nombre</label>
  4.       <input type="text" tabindex="1" value="" name="name" id="name"/>      <br/>
  5.       <label>E Mail</label>
  6.       <input type="text" tabindex="5" value="" name="email" id="email"/>       <br/>
  7.       <label>Telefono <span class="required">*</span></label>
  8.       <input type="text" tabindex="6" value="" name="telefono" id="telefono"/>       <br/>
  9.       </div>
  10.       <div class="contentcontact_right">
  11.       <fieldset class="checkbox_left">
  12.       <input tabindex="9" id="checkbox" type="checkbox" class="Check" name="checkbox[]" value="1"> <label class="field-checkbox">1</label><br>
  13.       <input tabindex="10" id="checkbox" type="checkbox" class="Check" name="checkbox[]" value="2"> <label class="field-checkbox">2</label><br>
  14.       <input tabindex="11" id="checkbox" type="checkbox" class="Check" name="checkbox[]" value="3"> <label class="field-checkbox">3</label>
  15.       </fieldset>
  16.       <fieldset class="checkbox_right">
  17.       <input tabindex="12" id="checkbox" type="checkbox" class="Check" name="checkbox[]" value="4"> <label class="field-checkbox">4</label>
  18.       <input tabindex="13" id="checkbox" type="checkbox" class="Check" name="checkbox[]" value="5"> <label class="field-checkbox">5</label>
  19.       <input tabindex="14" id="checkbox" type="checkbox" class="Check" name="checkbox[]" value="6"> <label class="field-checkbox">6</label>
  20.       </fieldset>
  21.       <input type="button" class="submit" onclick="submitAJAXForm(this);" value="enviar"/>
  22.       <input type="hidden" value="0" name="send" id="send" style="display: none;"/>
  23.       <input type="hidden" value="contactus" name="orgin" id="orgin" style="display: none;"/>
  24.       <input type="text" id="sel" value="" />
  25.       </form>
  26.       </div>
  27.     <script>
  28.     function submitAJAXForm(sub)
  29.     {
  30.         sub.setDisabled(true);    
  31.         sub.setValue(".. Enviado ..");    
  32.        
  33.         var ajax = new Ajax();
  34.         ajax.responseType = Ajax.FBML;
  35.  
  36.         ajax.ondone = function(data)
  37.         {
  38.             var msgdialog = new Dialog();
  39.             msgdialog.showMessage('Confirmation', 'The contact form has been submitted.');
  40.             return false;
  41.         }
  42.  
  43.         ajax.onerror = function() {
  44.             var msgdialog = new Dialog();
  45.             msgdialog.showMessage('Error', 'An error has occurred while trying to submit.');
  46.             return false;
  47.         }
  48.  
  49.         function valores(f) {
  50.         cual1 = 'checkbox[]';
  51.         todos = new Array();
  52.         for (var i = 0, total = f[cual1].length; i < total; i++) {
  53.                if (f[cual1][i].checked) todos[todos.length] = f[cual1][i].value;
  54.         }
  55.         document.getElementById('sel').value = todos.join(', ');
  56.         }
  57.        
  58.         // collect field values
  59.         var queryParams = {
  60.             'name' : document.getElementById('name').getValue(),
  61.             'email' : document.getElementById('email').getValue(),
  62.             'telefon' : document.getElementById('telefon').getValue(),
  63.             'sel' : document.getElementById('sel').getValue(),
  64.             'send' : document.getElementById('send').getValue(),
  65.             'origin' : document.getElementById('orgin').getValue(),
  66.         };
  67.         ajax.post('form_submit_ast.php?sys=fbpage', queryParams);
  68.         return false;
  69.     }
  70.     </script>

Código PHP:
Ver original
  1. <?php
  2.     $email.= "<b>Name             : </b>".trim($_POST['name'])."<br/>";
  3.     $email.= "<b>Email            : </b>".trim($_POST['email'])."<br/>";
  4.     $email.= "<b>Telefono          : </b>".trim($_POST['telefono'])."<br/>";
  5.     $email.= "".trim($_POST['sel'])."<br/>";
  6.    
  7.     $email.= print_r($_POST,true);
  8.    
  9.  
  10.     $headers = "From: [email protected]\r\n";
  11.     $headers .= "Content-Type: text/html";
  12.     mail(
  13.             "nombre <[email protected]>",
  14.             "Contact",
  15.             $email,
  16.             $headers
  17.     );

Última edición por gregory1012; 02/09/2010 a las 09:11
  #2 (permalink)  
Antiguo 02/09/2010, 09:26
 
Fecha de Ingreso: septiembre-2010
Mensajes: 3
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Capturar valores checkbox y envialos por Email

Nadie me puede ayudar?
  #3 (permalink)  
Antiguo 28/09/2010, 08:18
 
Fecha de Ingreso: marzo-2009
Mensajes: 76
Antigüedad: 15 años, 1 mes
Puntos: 1
Respuesta: Capturar valores checkbox y envialos por Email

Hola Gregory, intentalo hacerlo asi, se que parece igual pero mira lo que esta en negrita, creo que ahi esta el tema.

Tambien tengo que comentarte que si el checkbox es uno solo, lo pasa como dato y esta simple funcion no sirve, pero es simplemente una comprobacion mas.

function miFunction(){
cual = 'idsProveedores[]';
f= document.formFiltro;
todos = new Array();
for (var i2 = 0, totalIdsProveedores = f[cual].length; i2 < totalIdsProveedores; i2++)
if (f[cual][i2].checked) todos[todos.length] = "idsProveedores[]=" + f[cual][i2].value;

array = todos.join("&");
}

Espero que se entienda, saludos.

NicoStone.

Última edición por nicostone; 28/09/2010 a las 08:54

Etiquetas: ajax, checkbox, email
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 02:04.