Well, you can do it mostly with HTML, input’s, hidden inputs and some slightly odd logic.
Give each button an array name and assign a hidden version to each. That way when you post the form by picking a button, it will have the old values in place and will post those along with the button pressed. The logic of this is tricky. You have to keep the old values in place and check for changes. Then, you have to set the values of the changes and save them for the next pass. Also, you will need to either use indexing for the codes used or perhaps flag them in arrays. I tossed some code together that would do this in one manner. The cURL code is in place, but, had to add some extra code to create the URL to access. Not sure if any of this works. Just created it quickly. Test it first with without the cURL… I have them commented out and have it displaying the URL so you can see if it works for you.
<?PHP
// Set up an array of URL's for the hardware
$urls = array( "1"=>"http://192.168.1.10/led?state=TURN+RED+ON", "2"=>"http://192.168.1.20/led?state=TURN+RED+ON", "3"=>"http://192.168.1.30/led?state=TURN+RED+ON", "4"=>"http://192.168.1.40/led?state=TURN+RED+ON",
"6"=>"http://192.168.1.10/led?state=TURN+RED+OFF", "7"=>"http://192.168.1.20/led?state=TURN+RED+OFF", "8"=>"http://192.168.1.30/led?state=TURN+RED+OFF", "9"=>"http://192.168.1.40/led?state=TURN+RED+OFF");
// Get old values of buttons to set them ( If not set, set to default! )
$saved_buttons = $_POST["saved_buttons"];
if (!isset($saved_buttons[1])) { $saved_buttons[1] = "#1: Not Set"; }
if (!isset($saved_buttons[2])) { $saved_buttons[2] = "#2: Not Set"; }
if (!isset($saved_buttons[3])) { $saved_buttons[3] = "#3: Not Set"; }
if (!isset($saved_buttons[4])) { $saved_buttons[4] = "#4: Not Set"; }
$buttons = $saved_buttons;
// Check if any button was pressed. If so, alter that one button's setting and save it.
if (isset($_POST["buttons"])) {
$pressed_button = $_POST["buttons"];
foreach ($pressed_button as $button_number => $button_code) {
$code = substr($button_code, 5, 1);
if ($code=="o" OR $code=="n") {
$buttons[$button_number] = "#" . $button_number . ": Off";
$saved_buttons[$button_number] = "#" . $button_number . ": On";
$curl_url = $urls[$button_number];
} elseif ($code=="f") {
$buttons[$button_number] = "#" . $button_number . ": On";
$saved_buttons[$button_number] = "#" . $button_number . ": Off";
$curl_url = $urls[$button_number+5];
}
echo "URL: " . $curl_url . "<br>";
// Now, with the values of the buttons sorted out, send out the currect code to the hardware
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, $curl_url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $content = trim(curl_exec($ch));
// curl_close($ch);
}
}
?>
<html>
<body>
<form method="POST">
<input type="hidden" name="saved_buttons[1]" value="<?PHP echo $saved_buttons[1]; ?>">
<button type="submit" name="buttons[1]" value="<?PHP echo $buttons[1]; ?>"><?PHP echo $saved_buttons[1]; ?></button>
<input type="hidden" name="saved_buttons[2]" value="<?PHP echo $saved_buttons[2]; ?>">
<button type="submit" name="buttons[2]" value="<?PHP echo $buttons[2]; ?>"><?PHP echo $saved_buttons[2]; ?></button>
<input type="hidden" name="saved_buttons[3]" value="<?PHP echo $saved_buttons[3]; ?>">
<button type="submit" name="buttons[3]" value="<?PHP echo $buttons[3]; ?>"><?PHP echo $saved_buttons[3]; ?></button>
<input type="hidden" name="saved_buttons[4]" value="<?PHP echo $saved_buttons[4]; ?>">
<button type="submit" name="buttons[4]" value="<?PHP echo $buttons[4]; ?>"><?PHP echo $saved_buttons[4]; ?></button>
</form>
</body>
</html>
NOTE: There are other ways to keep the old versions. One would be sessions and you could write them out to a text file, but, using the hidden fields work quite well. I could not test the cURL since I do not have your hardware… Hope it works okay for you…