Created
April 4, 2015 15:12
-
-
Save CaiJimmy/b02fd3bd048040c74292 to your computer and use it in GitHub Desktop.
Simple PHP form
This file contains 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
<section id="form"> | |
<form action="/post.php" method="POST" id="contribuir"> | |
<section id="form-wrap"> | |
<input name="name" type="text" placeholder="Tu nombre*" id="nombre"/> | |
<input name="email" type="mail" placeholder="E-mail(No será publicado)" id="email"/> | |
<input name="titulo" type="text" placeholder="El titulo*"/> | |
<textarea rows="8" name="contenido" required="true" id="contenido" placeholder="El contenido*"></textarea> | |
<input type="submit" name="submit" id="submit" value="Enviar"> | |
</section> | |
</form> | |
</section> |
This file contains 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
<?php | |
$required = array('name', 'contenido', 'titulo'); | |
$error = false; | |
foreach($required as $field) { | |
if (empty($_POST[$field])) { | |
$error = true; | |
} | |
} | |
if ($error) { | |
echo "Todos los cuadros marcados con * son obligatorios."; | |
} else { | |
echo "Gracias por contribuir."; | |
$data = $_POST['name'] . ' - ' . $_POST['email'] . ' - ' . $_SERVER['HTTP_CF_CONNECTING_IP'] . "\n ------------------\n" . $_POST['titulo'] . "\n" .$_POST['contenido'] . "\n\n" ; | |
file_put_contents('recibidos.txt' , $data , FILE_APPEND | LOCK_EX); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment