Jump to content

Recommended Posts

Hi,

In the following code I'm using a combo box to select a relay and activate it. The code works but if I refresh the page, the last selected relay is activated again.

How can I reset the page to default to value '0' which has no relay control?

TIA

 

<!DOCTYPE html>
<html>
<head>
<title>Relay control</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2><center>Status y control de relés</center></h2>
<?php
$arrleds = array();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $selected_val = $_POST['sel'];

  if ($selected_val == '1'){
  $cmd = exec("sudo ./trigger.py b 0");
  }
  elseif ($selected_val == '2'){
  $cmd = exec("sudo ./trigger.py b 1");
  }
  elseif ($selected_val == '3'){
  $cmd = exec("sudo ./trigger.py b 2");
  }

  ....

  else {}
}

?>
<table class="center">
<tr>
 <td></td>
 <td><h1>Activación de relé</h1>
  <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
        <select name='sel' onchange='submit();'>
                <option value='0'>Sin activar</option> <!-- no action -->
                <option value='1'>Secadora 1</option>
                <option value='2'>Secadora 2</option>
                <option value='3'>Lavadora S</option>
                ....
        </select>
  </form>
 </td>
 <td></td>
</tr>
<tr>
 <td></td>
 <td><a href="index.php">Home</a>
 <td></td>
</tr>
</table>
</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/308439-refreshing-page-issue/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.