Last active
January 9, 2016 15:56
-
-
Save labra/9765275b1dbf7a1415fb to your computer and use it in GitHub Desktop.
Ejemplo de formulario
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http=require('http'); | |
var url = require('url'); | |
var qs = require('querystring'); | |
var server = http.createServer(function(req, res) { | |
switch (req.method) { | |
case 'POST': var body = ''; | |
req.on('data', function(data) { | |
body += data; | |
if (body.length > 1e6) req.connection.destroy(); | |
}); | |
req.on('end', function() { | |
var POST = qs.parse(body); | |
res.end("Hola " + POST.cliente + "! Tu email es:" + POST.correo); | |
}); | |
break; | |
case 'GET': if (url.parse(req.url, true).pathname == '/') { | |
datos = "<form action=\"procesa\" method=\"POST\">" | |
+ "<label>Nombre: <input name=\"cliente\"></label><br>" | |
+ "<label>Email: <input name=\"correo\" type=\"email\"></label><br>" | |
+ "<button>Enviar</button></form>"; | |
res.setHeader("Content-Type", "text/html"); | |
res.write(datos); | |
res.end(); | |
} | |
break; | |
default: console.log("Método no soportado" + req.method); | |
}}); | |
server.listen(3000); | |
console.log('Server listenning at port 3000'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment