I'm trying to get PHP to change a JavaScript file. I want to have a form with a simple toggle switch and password like this:
.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>
The form has a password and toggle switch. The PHP should validate the password, and if it is "1234", then if the toggle switch is checked, it will change the JavaScript file to "alert('ON');", if it is off, it will change to "alert('OFF');". There is a bookmarklet that will change functionality for what the form is at. The code is this
javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://shimmering-raspy-roarer.glitch.me/script.js';})();
I'm not sure how to write this PHP. I am using glitch.com to make this website.
First of all you don't need to change the Javascript file. only thing you need is write a condition whenever it was true, then show the alert.
For example:
<!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>