inde - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of inde.php

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <title>Página con validación en PHP</title>
  5.   <style>
  6.     .error-message {
  7.       color: red;
  8.     }
  9.   </style>
  10. </head>
  11. <body>
  12.   <h1>Página con validación en PHP</h1>
  13.  
  14.   <form method="POST" action="">
  15.     <input type="text" name="inputText">
  16.     <button type="submit">Validar</button>
  17.     <p class="error-message"><?php validarCampo(); ?></p>
  18.   </form>
  19.  
  20. <?php
  21. function validarCampo() {
  22.   if ($_SERVER["REQUEST_METHOD"] === "POST") {
  23.     $inputText = $_POST["inputText"];
  24.  
  25.     if (empty($inputText)) {
  26.       echo "¡Error! El campo está vacío.";
  27.     }
  28.     // Puedes agregar más validaciones aquí si lo deseas
  29.   }
  30. }
  31. ?>
  32. </body>
  33. </html>
  34.  
  35.  
File Description
  • inde
  • PHP Code
  • 24 May-2023
  • 672 Bytes
You can Share it: