fotofobikko Posted November 22, 2012 Report Share Posted November 22, 2012 Estimados tengo un formulario, que obtiene los datos de un carro de compra de otras paginas. Esa parte funciona bien, y se me ocurrio incluir un numero de serie o pedido. Como no manejo base de datos MySQL y los productos no pasan los 10, opte por incluir un contador de visitas y que las hiciera como numero se de serie o pedido. El problema, es que el archivo PHP (enviar.php) y que recibe los datos del formulario, no adjunta este numero y la verdad no se como hacerlo para que funcione. El codigo del formulario.php <html><head><title>Formulario</title><style type="text/css">.body {font-family: Arial;font-size: 10pt;font-style: normal;font-weight: normal;font-variant: normal;color: #000000;} .td {font-family: Arial;font-size: 10pt;font-style: normal;line-height: normal;font-weight: normal;font-variant: normal;color: #000000;} </style><SCRIPT LANGUAGE="Javascript"><!--function Enviar(form) {for (i = 0; i < form.elements.length; i++) {if (form.elements.type == "text" && form.elements.value == "") { alert("Por favor complete todos los campos del formulario"); form.elements.focus(); return false; }}form.submit();}// --></SCRIPT></head><body bgcolor="#FFFFFF" link="#32468D" vlink="#800080" class="body"><SCRIPT LANGUAGE="Javascript"> function alterError(value) {if (value<=0.99) {newPounds = '0';} else {newPounds = parseInt(value);}newPence = parseInt((value+.0008 - newPounds)* 100);if (eval(newPence) <= 9) newPence='0'+newPence;newString = newPounds + '.' + newPence;return (newString);} function showItems() {index = document.cookie.indexOf("TheBasket");countbegin = (document.cookie.indexOf("=", index) + 1); countend = document.cookie.indexOf(";", index); if (countend == -1) { countend = document.cookie.length; }fulllist = document.cookie.substring(countbegin, countend);totprice = 0; itemlist = 0;for (var i = 0; i <= fulllist.length; i++) {if (fulllist.substring(i,i+1) == '[') {itemstart = i+1;} else if (fulllist.substring(i,i+1) == ']') {itemend = i;thequantity = fulllist.substring(itemstart, itemend);itemtotal = 0;itemtotal = (eval(theprice*thequantity));temptotal = itemtotal * 100;var tax = itemtotal / 100 * (0 - 0); tax = Math.floor(tax * 100)/100totprice = totprice + itemtotal + tax;itemlist=itemlist+1;document.writeln('<INPUT TYPE="hidden" NAME="Producto'+itemlist+'" VALUE="'+theitem+'" SIZE="40">');document.writeln('<INPUT TYPE="hidden" NAME="Cantidad'+itemlist+'" VALUE="'+thequantity+'" SIZE="40">')document.writeln('<INPUT TYPE="hidden" NAME="ProductoTotal'+itemlist+'" VALUE="'+alterError(itemtotal)+'" SIZE="40">');} else if (fulllist.substring(i,i+1) == ',') {theitem = fulllist.substring(itemstart, i);itemstart = i+1;} else if (fulllist.substring(i,i+1) == '#') {theprice = fulllist.substring(itemstart, i);itemstart = i+1;}} document.writeln('<INPUT TYPE="hidden" NAME="Total" VALUE="'+alterError(totprice)+'" SIZE="40">'); }function Total() {document.writeln(alterError(totprice));} </SCRIPT><center> <table border="0" cellpadding="0" cellspacing="0" width="640" class="body"> <tr> <td width="50%"><big><big>Formulario</big></big></td> <td width="50%" align="right">[ <a href="carrito.htm">Carrito de Compra</a> | <a href="estado.htm">Estado</a> | Formulario ]</td> </tr> <tr> <td width="100%" colspan="2"> <hr size="1" color="#000000"> </td> </tr> <tr> <td width="100%" colspan="2"></td> </tr> </table> <FORM method="post" action="enviar.php" target="_top"> <table width="370" border="0" cellpadding="0" cellspacing="0" cols="2" class="body"> <td width="150"></td> <td width="220"> </td> </tr> <tr> <td width="150">Orden de Compra</td><td width="220" height="30"> <?// Este es el codigo PHP que lee y guardar el ultimo numero de pedido// Necesita un archivo TXT para leerlo$archivo = "numpedido.txt"; $abre = fopen($archivo, "r"); $total = fread($abre, filesize($archivo)); fclose($abre); $abre = fopen($archivo, "w"); $total = $total + 1; $grabar = fwrite($abre, $total); fclose($abre); echo "<font face='Arial'>Nº: ".$total."</font>"; // Esto es lo que se muestra como resultado?> <label></label></td> </tr> <tr> <td width="150" height="30"> </td> <td width="220" height="15"><label for="pedido"></label></td> </tr> <tr> <td width="150" height="30">Nombre</td> <td height="15"><input type="text" name="Nombre" size=34></td> </tr> <tr><td width="150">RUT</td><td width="220" height="30"><input type="text" name="RUT" size=34 id="RUT"></td></tr><tr><td width="150">Domicilio</td><td width="220" height="30"><input type="text" name="Domicilio" size=34 id="Domicilio"></td></tr><tr><td width="150">Ciudad</td><td width="220" height="30"><input type="text" name="Ciudad" size=34></td></tr><tr><td width="150">Comuna</td><td width="220" height="30"><input type="text" name="Comuna" size=34 id="Comuna"></td></tr><tr><td width="150">E-mail</td><td width="220" height="30"><input type="text" name="Email" size=34 id="Email"></td></tr><tr><td width="150">Teléfono</td><td width="220" height="30"><input type="text" name="Telefono" size=34 id="Telefono"></td></tr><tr> <td width="150">Instrucciones</td> <td width="220" height="30"><label> <textarea name="Mensaje" cols="34" rows="8" id="Mensaje"></textarea> </label></td></tr> <SCRIPT LANGUAGE="Javascript">showItems();</SCRIPT> <tr> <td width="150">Total:</td> <td width="220" height="30">$ <SCRIPT LANGUAGE="Javascript">Total()</SCRIPT> </td> </tr> <tr> <td width="150"><br><br></td> <td width="220"> <input type="button" value="Enviar" onclick="return Enviar(this.form)"> <input type="reset" value="Restablecer"> </td> </tr> </table></form> </center></body></html> Una vez que se envia el formulario el archivo enviar.php se encarga de recibir los datos y enviarlo a los mail asignados: ENVIAR.PHP <?$MailToAddress = "[email protected]";$MailSubject = "Pedido En Linea"; if (!$MailFromAddress) { $MailFromAddress = $_POST['Email']; } $Header = "Orden de Compra Nº" ; // La idea es que el numero de pedido quede aquí pero, no lo muestra$Footer = ""; if (!is_array($HTTP_POST_VARS)) return; reset($HTTP_POST_VARS); while(list($key, $val) = each($HTTP_POST_VARS)) { $GLOBALS[$key] = $val; $val=stripslashes($val); $Message .= "$key = $val\n"; } if ($Header) { $Message = $Header."\n\n".$Message."\n\n"; } $Message .= "REMOTE HOST: ".$REMOTE_HOST."\n"; $Message .= "REMOTE USER: ". $REMOTE_USER."\n"; $Message .= "REMOTE ADDR: ". $REMOTE_ADDR."\n"; if ($Footer) { $Message .= "\n\n".$Footer; } mail( "$MailToAddress", "$MailSubject", "$Message", "From: $MailFromAddress");mail( $_POST['Email'],"Detalle de su compra en nuestro website","$Message", "From: [email protected]");header ("Location: http://www.dominio.cl/gracias.html");?> Alguna idea de como hacer que el numero se incluya en el envio del formulario? Solo eso necesito lo demas esta OK... Saludos y gracias de ante mano Link to comment Share on other sites More sharing options...
cañangasñangas Posted November 22, 2012 Report Share Posted November 22, 2012 en esta linea: echo "<font face='Arial'>Nº: ".$total."</font>"; podrias agregar un input hidden con el valor total: echo '<font face="Arial">Nº: '.$total.'</font><input type="hidden" name="total" value="'.$total.'">'; ve como andas con eso y claro obtienes el numero con $_POST["total"] saludos Link to comment Share on other sites More sharing options...
fotofobikko Posted November 22, 2012 Author Report Share Posted November 22, 2012 Amigo, gracias por responder... segui tu idea y cambie la linea echo, pero al enviar el formulario, el archivo enviar.php y que recibe los datos envia un error: Parse error : error de sintaxis, inesperado T_VARIABLE en / home / localhost / public_html / carnes / enviar.php en la línea 8 En la linea 8 inclui tu codigo y quedo asi: $Header = "Orden de Compra Nº" $_POST["total"]; Ok, el codigo o linea :echo '<font face="Arial">Nº: '.$total.'</font><input type="hidden" name="total" value="'.$total.'">'funciona y se visualiza en el archivo formulario.php, pero no lo recibe el archivo enviar PHP... Alguna otra idea? Link to comment Share on other sites More sharing options...
AshWilliams Posted November 22, 2012 Report Share Posted November 22, 2012 $Header = "Orden de Compra Nº".$_POST["total"]; Faltaba concatenar ...por eso puse el punto tan visible Saludos :krider: Link to comment Share on other sites More sharing options...
fotofobikko Posted November 22, 2012 Author Report Share Posted November 22, 2012 $Header = "Orden de Compra Nº".$_POST["total"]; Faltaba concatenar ...por eso puse el punto tan visible Saludos :krider: :woot: EXCELENTE!!!!! Ahora resulto.... :woot: :woot: :woot: :woot: Gracias por los consejos... a los 2! Saludos!!! Link to comment Share on other sites More sharing options...
cañangasñangas Posted November 22, 2012 Report Share Posted November 22, 2012 $Header = "Orden de Compra Nº".$_POST["total"]; Faltaba concatenar ...por eso puse el punto tan visible Saludos :krider: :woot: EXCELENTE!!!!! Ahora resulto.... :woot: :woot: :woot: :woot: Gracias por los consejos... a los 2! Saludos!!! Como no me di cuenta que no habias concatenado, bueno solucionado procedo a cerrar Saludos. ;) Link to comment Share on other sites More sharing options...
Recommended Posts