Problem of web control

Previously I have asked the question on web control for my project, thanks to some nice people, I can finally build my code and test the website control

I am currently try to use the web control led code template to control the motor. The setup is to connect the photon with L293D motor module .

When I click “foward” in html = the motor moves clockwise & anticlockwise motion interchanging
When I click “left” in html = it moves in one side, stop and start back
When I click “right” in html = it moves in another side, stop and start back
When I click stop, it stops

Here is the coding

int led1 = D2;
int led2 = D3;
bool forward ;
bool left;
bool right;
bool toggle;
int count;
int last = 0;

void setup()
{

   pinMode(led1, OUTPUT);
   pinMode(led2, OUTPUT);    

   Particle.function("led",ledToggle);

   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);

}

 void loop()
{
   if(forward)
   {
      if(millis() - last >= 500)
      {
        last = millis();
        
        if(toggle = !toggle)
        {
           digitalWrite(led1, HIGH);
           digitalWrite(led2, LOW);
        }
        else
        {
           digitalWrite(led1, LOW);
           digitalWrite(led2, HIGH);
        }
        if(--count == 0){
           forward = false;
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        }
      }
   }
   
   if(left)
   {
      if(millis() - last >= 500)
      {
        last = millis();
        
        if(toggle = !toggle)
        {
           digitalWrite(led1, HIGH);
           digitalWrite(led2, LOW);
        }
        else
        {
           digitalWrite(led1, LOW);
           digitalWrite(led2, LOW);
        }
        if(--count == 0){
           left = false;
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        }
      }
   }
   
   if(right)
   {
      if(millis() - last >= 500)
      {
        last = millis();
        
        if(toggle = !toggle)
        {
           digitalWrite(led1, LOW);
           digitalWrite(led2, HIGH);
        }
        else
        {
           digitalWrite(led1, LOW);
           digitalWrite(led2, LOW);
        }
        if(--count == 0){
           right = false;
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        }
      }
   }
}

int ledToggle(String command) {
if(command == "forward")
   {
        forward = true;
        count = 2000;
        return 0;
    }
   else if(command == "left")
   {
       left = true;
       count = 2000;
        return -1;
   }
   else if(command == "right")
   {
       right = true;
       count = 2000;
        return 2;
   }
   else
   {
       forward = false ;
       left = false;
       right = false;
       
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        return 1;
   }
}

The html file coding is as follow

/* Paste the code between the dashes below into a .txt file and save it as an .html file. Replace your-device-ID-goes-here with your actual device ID and your-access-token-goes-here with your actual access token.

---------------------------
<!-- Replace your-device-ID-goes-here with your actual device ID
and replace your-access-token-goes-here with your actual access token-->
<!DOCTYPE>
<html>
  <body>
  <center>
  <br>
  <br>
  <br>
  <form action="https://api.particle.io/v1/devices/xxxxxx/led?access_token=yyyyyy" method="POST">
    Tell your device what to do!<br>
    <br>
    <input type="radio" name="args" value="forward">Forward motion.
    <br>
    <input type="radio" name="args" value="left">Left motion.
    <br>
    <input type="radio" name="args" value="right">Right motion.
    <br>
    <input type="radio" name="args" value="stop">Stop motion.
    <br>
    <br>
    <input type="submit" value="Do it!">
  </form>
  </center>
  </body>
</html>
---------------------------
*/

I can use html file to run it, however, it is quite troublesome to have the feedback message each time I choose the action

Thanks to Moors7, he provided a tutorial from bko,

Tutorial: Spark Variable and Function on One Web Page

Also here

Controlling the Spark Core pins with webpage buttons

I still cannot understand the java programming code, can anyone please teach me how to implement it?

Thanks