The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Form-Handler, LWIP running on ARM Cortex Processor
shawn.t
post Jun 9 2020, 01:24 PM
Post #1





Group: Members
Posts: 3
Joined: 9-June 20
Member No.: 27,389



Hello community, I am running the code below:

CODE

<tr>
<td><input value="PROGRAM" type="submit"></td>
</tr>
<tr>
<td><input value="SAVE SCENE" type="button" onclick="msg()"></td>
<script>
     <form method="get" action="/leds.cgi"></form>  
    function msg()
    {
      alert("Hello world!");
    }
    </script>
</tr>


The code runs smoothly with LWIP on my ARM Cortex Processor - with the "PROGRAM" button I am calling the form-handler(CGIhandler) and the code executes accordingly.

I want to execute a different function in my C Code when the "SAVE SCENE" button is pressed and I am not too sure how to do that. I currently have checkboxes on my webpage and when the "PROGRAM" button is pressed I process the string accordingly:
CODE
http://192.168.0.36/leds.cgi?led=1&led=2&led=6&led=8

Checkbox code:
CODE
"<input value=\"%u\" name=\"led\" type=\"checkbox\" checked>"

Each checkbox is assigned a number and when the form-handler is called I process that accordingly in my C Code.

I want to know if there is a way that I can assign a number or different keyword to the "SAVE SCENE" button and when that button is pressed it calls the same form-handler which will enable me to process it in my C Code.

Thanks

This post has been edited by shawn.t: Jun 9 2020, 01:26 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 9 2020, 03:06 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,653
Joined: 10-August 06
Member No.: 7



If both are submit buttons with NAME attributes, the server side script can identify each button by its name/value pair.

BTW the code example is invalid, you can't put HTML code like FORM inside SCRIPT, also the INPUT elements need to be inside the FORM.


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shawn.t
post Jun 9 2020, 04:33 PM
Post #3





Group: Members
Posts: 3
Joined: 9-June 20
Member No.: 27,389



QUOTE(Christian J @ Jun 9 2020, 03:06 PM) *

If both are submit buttons with NAME attributes, the server side script can identify each button by its name/value pair.

BTW the code example is invalid, you can't put HTML code like FORM inside SCRIPT, also the INPUT elements need to be inside the FORM.


Thanks for the reply. Completely new to HTML, only know C Language.

The server side script is LWIP running on an ARM Processor - don't think it's the same as on a "traditional server".

I've tried identifying the button by it's name, but it keeps on calling the same CGIhandler(form-handler).

Can you please be so kind as to give me an example on how to put a name/value pair to a button?

I'll also put snippets of my C-code, not too sure how familiar you are with it:
CODE
/* USER CODE BEGIN PV */

// just declaring the function for the compiler [= CGI #2 =]
const char* LedCGIhandler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]);

// in our HTML file <form method="get" action="/leds.cgi"> [= CGI #3 =]
const tCGI LedCGI = {"/leds.cgi", LedCGIhandler};

// [= CGI #4 =]
tCGI theCGItable[1];

// just declaring SSI handler function [* SSI #1 *]
u16_t mySSIHandler(int iIndex, char *pcInsert, int iInsertLen);

// [* SSI #2 *]
#define numSSItags 16

// [* SSI #3 *]
char const *theSSItags[numSSItags] = {"t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "t10", "t11", "t12", "t13", "t14", "t15", "t16"};

//HANDLING THE CGI CALL:
const char* LedCGIhandler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])
{
    uint32_t i = 0;

    if (iIndex == 0)
    {
        checkedPoints[0] = 0;
        checkedPoints[1] = 0;
        checkedPoints[2] = 0;
        checkedPoints[3] = 0;
        checkedPoints[4] = 0;
        checkedPoints[5] = 0;
        checkedPoints[6] = 0;
        checkedPoints[7] = 0;
        //turning the LED lights off
        GPIOI->ODR &= ~(LED_RED_Pin);
    }

    for (i = 0; i < iNumParams; i++)
    {

        if (strcmp(pcParam[i], "led") == 0)

        {
            if (strcmp(pcValue[i], "1") == 0)
            {
                GPIOI->ODR |= LED_RED_Pin;
                // LD3 LED (red) on the board is ON!
                checkedPoints[0] |= 0x00000001;
            }
            else if (strcmp(pcValue[i], "2") == 0)
            {
                //HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
                // LD2 LED (blue) on the board is ON!
                checkedPoints[0] |= 0x00000002;
            }

            else if (strcmp(pcValue[i], "3") == 0)
            {
                //HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
                // LD2 LED (blue) on the board is ON!
                checkedPoints[0] |= 0x00000004;
            }

            else if (strcmp(pcValue[i], "4") == 0)
            {
                //HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
                // LD2 LED (blue) on the board is ON!
                checkedPoints[0] |= 0x00000008;
            }
//The conditional statements just continue for all buttons present.

//I also have a SSIhandler which gets called to "update" my HTML Page as to remember the state of the checkboxes:
u16_t mySSIHandler(int iIndex, char *pcInsert, int iInsertLen)
{

    uint16_t checkPointer;
    uint32_t pointCheck;

    char myStr1[80];

    checkPointer = iIndex / 32;
    pointCheck = (uint32_t)(1U << (iIndex % 32));


    if ((checkedPoints[checkPointer] & pointCheck) == 1)
    {
        sprintf(myStr1, "<input value=\"%u\" name=\"led\" type=\"checkbox\" checked>",(iIndex+1));

        strcpy(pcInsert, myStr1);

        return strlen(myStr1);
    }

    else
    {
        sprintf(myStr1, "<input value=\"%u\" name=\"led\" type=\"checkbox\">",(iIndex+1));

        strcpy(pcInsert, myStr1);

        return strlen(myStr1);
    }


Every time I press either the "PROGRAM" or "SAVE SCENE" button it calls the ledsCGIHandler function and I run through this piece of code to check which checboxes have been ticked:
CODE
for (i = 0; i < iNumParams; i++)
    {

        if (strcmp(pcParam[i], "led") == 0)

        {
            if (strcmp(pcValue[i], "1") == 0)
            {
                GPIOI->ODR |= LED_RED_Pin;
                // LD3 LED (red) on the board is ON!
                checkedPoints[0] |= 0x00000001;
            }
            else if (strcmp(pcValue[i], "2") == 0)
            {
                //HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
                // LD2 LED (blue) on the board is ON!
                checkedPoints[0] |= 0x00000002;
            }

            else if (strcmp(pcValue[i], "3") == 0)
            {
                //HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
                // LD2 LED (blue) on the board is ON!
                checkedPoints[0] |= 0x00000004;
            }


I'm looking for the keyword "led" and then for the number associated with each tickbox, I'm not looking for any "name" associated with the "PROGRAM" or "SAVE SCENE" button.

Thanks for your help.

This post has been edited by shawn.t: Jun 9 2020, 04:39 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 9 2020, 05:05 PM
Post #4


.
********

Group: WDG Moderators
Posts: 9,653
Joined: 10-August 06
Member No.: 7



The submit buttons might look like this:

CODE
<input name="foo" value="PROGRAM" type="submit">
<input name="bar" value="SAVE SCENE" type="submit">

Since the form uses the GET method*, the name/value of each form field (including those of the submit buttons) will be part of the URL's query string. So with the above buttons, the URL might become something like

CODE
http://192.168.0.36/leds.cgi?led=1&led=2&led=6&led=8&foo=PROGRAM

or

CODE
http://192.168.0.36/leds.cgi?led=1&led=2&led=6&led=8&bar=SAVE+SCENE

depending on the which submit button that was pressed. The name/value pairs of submit buttons are no different than those of the other form fields in the query string, so the C program should be able to find them in the same way.

*If you instead use the POST method, the form data will be sent directly to the form handling CGI script, without appearing in the URL.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shawn.t
post Jun 10 2020, 03:19 AM
Post #5





Group: Members
Posts: 3
Joined: 9-June 20
Member No.: 27,389



Got it thanks so much!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 05:50 PM