Friday, December 15th 2017, 10:30pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

leonarff

Beginner

Date of registration: Oct 2nd 2013

Posts: 6

1

Thursday, May 28th 2015, 9:21pm

Help Create a Button

Could anyone help me ?How can I create a web page with button that instructs server to turn on ou turn off something ?
The examples with forms works but I donĀ“t get to identify that a simple button was pressed and what button.
Thanks a lot.

Leonardo F. Farah

SEGGER - Oliver

Super Moderator

Date of registration: Nov 14th 2007

Posts: 41

2

Friday, May 29th 2015, 11:23am

Hello Leonardo,

Even a button needs to be part of a form as the <form> tag defines which action to take when the button is clicked.
In this case the button would be a submit button, even if you name and label it with something else. Its purpose is to
submit.

If you want one on and another off button, you will either have to work with Javascript to let the button set a specific
value that then can be submitted or you will have to use two form fields with one button each.

Which button has been submitted can then be identified by the Web Server functions by the button name or value that
has been specified. Everything else in your HTML code works like for any other standard Web Server.


Hope this gives you a push into the right direction.

Best regards,
Oliver

leonarff

Beginner

Date of registration: Oct 2nd 2013

Posts: 6

3

Friday, May 29th 2015, 3:27pm

Hello Oliver,

Thank you for your help.
I get the pressed button using the _callback_DefaultHandler of the cgi table ( WEBS_CGI ).

Interestingly, the list is not only used for CGI coding "< ! - # Exec cgi = " anything " ->".

Best regards,

Leonardo F. Farah

SEGGER - Oliver

Super Moderator

Date of registration: Nov 14th 2007

Posts: 41

4

Friday, May 29th 2015, 5:29pm

Hello Leonardo,

Quoted

I get the pressed button using the _callback_DefaultHandler of the cgi table ( WEBS_CGI ).
This happens because you do not have a CGI handler of the same name as your button installed.
Let's have a look at the formGET.htm as an example:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	<!--            	-->
	<!-- Toggle LEDs	-->
	<!--            	-->
	<P><B>Set/clear LEDs:</B></P>
	<FORM ACTION="" METHOD="GET">
  	<p>
    	<input <!--#exec cgi="LED0"--> type="checkbox" name="LED0">LED0 &nbsp; 
    	<input <!--#exec cgi="LED1"--> type="checkbox" name="LED1">LED1 &nbsp; 
    	<input <!--#exec cgi="LED2"--> type="checkbox" name="LED2">LED2 &nbsp; 
    	<input <!--#exec cgi="LED3"--> type="checkbox" name="LED3">LED3 &nbsp; 
    	<input <!--#exec cgi="LED4"--> type="checkbox" name="LED4">LED4 &nbsp; 
    	<input <!--#exec cgi="LED5"--> type="checkbox" name="LED5">LED5 &nbsp; 
    	<input <!--#exec cgi="LED6"--> type="checkbox" name="LED6">LED6 &nbsp; 
    	<input <!--#exec cgi="LED7"--> type="checkbox" name="LED7">LED7 &nbsp; 
    	<INPUT TYPE="submit" VALUE="Change" name = "SetLEDs">
  	</p>
	</FORM>


The button has been assigned the name "SetLEDs". This means if you want to do anything with this button you will have to install a handler for this name into the CGI table:

C/C++ Source code

1
  {"SetLEDs",   	_callback_SetLEDs           	},


For multiple buttons you will need to install multiple handlers as well.
Depending on the handler that is called you can now identify the pressed button.

In case you want to use the same handler for multiple buttons this would make it necessary to use Javascript and will make it a little more complex.

Best regards,
Oliver