Estoy tratando de hacer que PHP cambie un archivo JavaScript. Quiero tener un formulario con un interruptor de palanca simple y una contraseña como esta:
.switch { position: relative; display: inline-block; width: 60px; height: 34px; } .switch input { opacity: 0; width: 0; height: 0; } .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: .4s; transition: .4s; } .slider:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; -webkit-transition: .4s; transition: .4s; } input:checked + .slider { background-color: #2196F3; } input:focus + .slider { box-shadow: 0 0 1px #2196F3; } input:checked + .slider:before { -webkit-transform: translateX(26px); -ms-transform: translateX(26px); transform: translateX(26px); } /* Rounded sliders */ .slider.round { border-radius: 34px; } .slider.round:before { border-radius: 50%; } <!DOCTYPE html> <html> <head> </head> <body> <form action = "something.php"> <input type = "password" placeholder = "Password..." name = "PASSWORD" id = "password"><br><br> <label class="switch"> <input type = "checkbox" name = "TOGGLE" id = "toggleSwitch"> <span class="slider round"></span> </label> </form> </body> </html>El formulario tiene una contraseña y un interruptor de palanca. El PHP debe validar la contraseña, y si es "1234", entonces si el interruptor de palanca está marcado, cambiará el archivo JavaScript a "alerta ('ON');", si está desactivado, cambiará a " alerta('APAGADO');". Hay un bookmarklet que cambiará la funcionalidad en la que se encuentra el formulario. el codigo es este
javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://shimmering-raspy-roarer.glitch.me/script.js';})();No estoy seguro de cómo escribir este PHP. Estoy usando glitch.com para hacer este sitio web.
En primer lugar, no necesita cambiar el archivo Javascript. lo único que necesita es escribir una condición siempre que sea verdadera, luego mostrar la alerta.
Por ejemplo:
<!DOCTYPE html> <html> <head></head> <body> <form> <input type = "password" placeholder = "Password..." name = "PASSWORD" id = "password"><br><br> <label class="switch"> <input type = "checkbox" name = "TOGGLE" id = "toggleSwitch"> <span class="slider round"></span> </label> <input type="submit"> </form> <script> <!-- The alert code here --> <?php if ($_GET['PASSWORD'] == 1234) { $message = $_GET['TOGGLE'] ? 'ON' : 'OFF'; echo "alert('$message');"; } ?> </script> </body> </html>