Skip to content

Instantly share code, notes, and snippets.

@CaiJimmy
Created April 4, 2015 15:12
Show Gist options
  • Save CaiJimmy/b02fd3bd048040c74292 to your computer and use it in GitHub Desktop.
Save CaiJimmy/b02fd3bd048040c74292 to your computer and use it in GitHub Desktop.
Simple PHP form
<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>
<?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