Jump to content
ebolisa

refreshing page issue

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>

 

Share this post


Link to post
Share on other sites

@gw1500se is correct, you would use PRG (Post/Redirect/Get). You would not need Sessions in this case.

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.