Redirect from 'http in' API url

When I submit a form HTTP POST takes the browser to the form action API url. How can I (if it’s possible) redirect back to my form page so users can make another selection without having to hit the back button? I’ve tried onsubmit and onclick but think they’re overridden by the original POST element.

Below is the code for one of my form submits

<form action="https://api.electricimp.com/v1/xxxxxxxxxx/xxxxxxxxxxxxx" method="POST"><input id="VALUE" type="HIDDEN" name="VALUE" value="1" /><input type="SUBMIT" value="PERSONAL" /></form>&nbsp;

TIA

I assume you’re using HTML on a web page?

One issue that happens now is the returning “OK” message. There are agents in the works that will be making all of that much easier. But for now, you’ll have to use PHP.

If you use PHP (mixed with your HTML), you can submit the form and redisplay the page. There will be a refresh, which you will see. You can also post to the imp and redirect anywhere you wish by using PHP.

If no refresh is wanted, you’ll have to use AJAX, which is a combination of PHP and javascripting.

Not sure what you will be posting to the imp … can you list the entire form?

or …

You probably have a web page that you are going to use and you don’t want to post it here (because then anyone can click on it), so make a copy of your web page and call it something like “test.html”, or “test.php”. Then give us a link to it. I mention this because there are a few different ways to approach the project and it will be good to see what you are doing.

Hi thanks for replying

Basically I’m sending values to the Imp via 5 separate HTTP IN vimp’s, Everything works OK but, I want the form page to refresh after a submission ready for another submission rather than staying on the ‘OK’ page at the API url forcing me to use the back button.

My page code is below, however, I’ve obscured the API key details

`

=""> adaptiveid.html Welcome to AdaptiveID

Select the required Identity
 
         
`

Hopefully you have your website online (shared webhost) that has PHP.
If you have your own server, you should have PHP installed.

Below is a test PHP script to send values to an imp. You only need one HTTP IN node. Each button sends a different value. In my example, I only have two … but you can have as many as you want.

This is the working test page so you can see how the refresh looks:
http://www.catpin.com/imp

The script was used for a “OPEN” and “CLOSE” test that I was using with an imp.

It is using PHP CURL functions to do the post. This handles the header, posted values, and ignoring the “OK” returned back.

Here is the PHP script (called “index.php” on my test page):

`<?php

$v = $_POST[‘v’];

if($v == “0” || $v == “1”)
{
$rURL = “https://api.electricimp.com/v1/cg9x1/3094a7/?value=”.$v;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rURL);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$out = curl_exec($ch);
curl_close($ch);	

}
?>

Imp Test Page html, body { margin:0px auto; text-align:center; } form { float:left; } .submit:hover { background-color:#99ccff; }

#content {
margin:0px auto;
margin-top:150px;
width:260px;
text-align:center;
}

`

Hi mlseim, thanks again for your help, I’ll have to have a read about php as I don’t fully understand what’s going on with it. I’ll let you know how I get on although it might be next weekend before I get to play again.

All the best

Dougie