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.
Result of php executing
Full code of inde.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>Página con validación en PHP</title>
- <style>
- .error-message {
- color: red;
- }
- </style>
- </head>
- <body>
- <h1>Página con validación en PHP</h1>
- <form method="POST" action="">
- <input type="text" name="inputText">
- <button type="submit">Validar</button>
- <p class="error-message"><?php validarCampo(); ?></p>
- </form>
- <?php
- function validarCampo() {
- if ($_SERVER["REQUEST_METHOD"] === "POST") {
- $inputText = $_POST["inputText"];
- if (empty($inputText)) {
- echo "¡Error! El campo está vacío.";
- }
- // Puedes agregar más validaciones aquí si lo deseas
- }
- }
- ?>
- </body>
- </html>