Author Topic: How to create an action using a button on the webpage?  (Read 1927 times)

Bua

  • Sr. Member
  • ****
  • Posts: 34
    • View Profile
How to create an action using a button on the webpage?
« on: April 04, 2014, 12:02:56 AM »
Hi

I just want to reset some parameters when a user click the "Reset" button on the PosturePlane.html.

I tried to use HTTPExecutePost and HTTPPrint functions (one at a time) because I don't know how to write a html to call a function from my firmware.

Below is the code when I tried with HTTPExecutePost in my CustomHTTPApp.c.

Code: [Select]

#if defined(HTTP_USE_POST)
                extern int avgAngleAll;
                extern DWORD noOfStretch;
                static HTTP_IO_RESULT HTTPPostReset(void);
#endif

HTTP_IO_RESULT HTTPExecutePost(void)
{
    DEBUG_PUT_STR(DEBUG_LEVEL_INFO, "\nHTTPExecutePost()");    //MODTRONIX added this line

// Resolve which function to use and pass along
BYTE filename[20];

// Load the file name
// Make sure BYTE filename[] above is large enough for your longest name
MPFSGetFilename(curHTTP.file, filename, sizeof(filename));

        if(!memcmppgm2ram(filename, "protect/PosturePlane.htm", 24))
return HTTPPostReset();

        cmdParseHTTPPost();

return HTTP_IO_DONE;
}

static HTTP_IO_RESULT HTTPPostReset(void)
{
    noOfStretch = 0;
    avgAngleAll = 0;
           
    return HTTP_IO_DONE;
}


Another part in PosturePlane.html.

Code: [Select]
<form name="input" action="" method="post">
<input type="submit" value="Reset">
</form>

This did not work, I suspect that because I did't pass any variable here.
================================================================
I also tried to use the HTTPPrint_reset.

In CustomHTTPApp.c
Code: [Select]
extern int avgAngleAll;
extern DWORD noOfStretch;
void HTTPPrint_reset(void)
{
    noOfStretch = 0;
    avgAngleAll = 0;
}

In PosturePlane.html
Code: [Select]
<form name="input" action="~reset~" method="post">
<input type="submit" value="Reset">
</form>

This code make it called ~reset~ every time the web page refresh, so it did not work. 

Can someone give me an example, how to call a c code function from html?

Thanks,
Bua

« Last Edit: April 06, 2014, 03:10:30 AM by Bua »

Bua

  • Sr. Member
  • ****
  • Posts: 34
    • View Profile
Re: How to create an action using a button on the webpage?[Solved]
« Reply #1 on: April 06, 2014, 03:12:43 AM »
I found the problem.  In HTTP_IO_RESULT HTTPExecutePost(void), BYTE filename[20], but if(!memcmppgm2ram(filename, "protect/PosturePlane.htm", 24)).  I need to increase filename to 25, and then it works.