Buttons
[Previous] [Main] [Next]

 
Button objects are added to htmlForm objects using the << insertion operator or the Add() method. There are three types of buttons available for use on forms:  
  • submit button
  • reset button
  • clickable image button
 
Each type of button is represented by the html++ classes htmlInputSubmit, htmlInputReset, and htmlInputImage, respectively. EVERY form must contain at least one submit button.  
 
Both submit and image buttons cause the action URL of the form to be invoked, passing data from the form to the server. Reset buttons act locally to clear the fields on a form to their default state.  
 
Submit Buttons
You may have more than one submit button on a form. The htmlInputSubmit constructor allows you to specify a visible label and a field name for the button. You can also specify these parameters using the Label() and Name() methods.  
 
Most browsers render a standard submit method (one without a specific label or name) as a rectangle with the default label of "Submit" on it. Otherwise, the button will be labeled with the value you specify. If you specify a name for the button, the browser will send the button name and it's label as a name/value pair along with the rest of the form contents to the server. This is how you identify which button was pressed if more than one button is present on a form.  
 
Reset Buttons
Reset buttons are represented by the htmlInputReset class. Reset buttons do not initiate a response from the server. Instead, they cause the browser to reset, or clear, form fields back to their default values. Unless a label is specified for a reset button, the browser will place the word "Reset" on it by default.  
 
Clickable Image Buttons
The htmlInputImage class allows you to create your own custom buttons from any image file URL. The buttons are called "clickable image" buttons, and act the same as a regular submit button, causing the browser to transmit form contents to the server.  
 
The x,y coordinates of the mouse within the image, relative to the top left corner of the image, are transmitted to the server as part of the form data. These values are assigned the image name (as specified in the constructor or the Name() method) plus a suffix of ".y" and ".y", respectively. Your form-processing application can use the x,y coordinates to enable custom behavior, or it can ignore the data entirely.  
 
Multiple Buttons on a Single Form
You can place multiple buttons on a form, but each button should have a unique label. The only exception is reset buttons. You can also make each button have a unique name, but it's usually more convenient to have all submit buttons share a single name. That way, your form processing application only has to check the value for the single field name to determine which button was pressed.  
 
You can place multiple clickable image buttons on a form as well, but since they do not have labels you must give each one a unique name in order to distinguish them.  
 
 
 
Submit Button Example
 
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page( "html++ example application" ) ;  
 
   htmlForm  form( "/cgi-bin/action.exe" ) ;  
   form << "Three button examples" << htmlParagraph()  
        << htmlInputSubmit() << htmlBreak()  
        << htmlInputSubmit( "Forward" ) << htmlBreak()  
        << htmlInputSubmit( "Backward""back_button" ) ;  
 
   page << form ;  
 
   server << page ;  
   return 0 ;  
}  
 
Submit Button Example Output
 
Content-Type: text/html  
<HTML>  
<HEAD>  
<TITLE>html++ example application</TITLE>  
</HEAD>  
<BODY>  
<FORM ACTION="/cgi-bin/action.exe" METHOD="POST">  
Three button examples<P></P>  
<INPUT TYPE="SUBMIT"><BR>  
<INPUT TYPE="SUBMIT" VALUE="Forward"><BR>  
<INPUT TYPE="SUBMIT" VALUE="Backward" NAME="back_button"></FORM>  
</BODY>  
</HTML>  
 

ex_button1.gif  

 



Reset Button Example
 
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page( "html++ example application" ) ;  
   htmlParagraph  p ;  
 
   htmlForm  form( "/cgi-bin/action.exe" ) ;  
   form << "A form with a Reset button" << p  
        << "Enter username: "  
        << htmlInputText( "username" ) << p  
        << htmlInputSubmit( "Login" ) << p  
        << htmlInputReset( "Clear" ) ;  
 
   page << form ;  
 
   server << page ;  
   return 0 ;  
}  
 
Reset Button Example Output
 
Content-Type: text/html  
<HTML>  
<HEAD>  
<TITLE>html++ example application</TITLE>  
</HEAD>  
<BODY>  
<FORM ACTION="/cgi-bin/action.exe" METHOD="POST">  
A form with a Reset button<P></P>  
Enter username: <INPUT TYPE="TEXT" NAME="username"><P></P>  
<INPUT TYPE="SUBMIT" VALUE="Login"><P></P>  
<INPUT TYPE="RESET" VALUE="Clear"></FORM>  
</BODY>  
</HTML>  
 

ex_button2.gif  

 
 
 
Clickable Image Button Example
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page( "html++ example application" ) ;  
 
   htmlForm  form( "/cgi-bin/action.exe" ) ;  
   form << "Clickable image button example"  
        << htmlParagraph()  
        << "Enter username: "  
        << htmlInputText( "username" )   
        << htmlParagraph()  
        << htmlInputImage( "login", "/images/login.gif" ) ;  
 
   page << form ;  
 
   server << page ;  
   return 0 ;  
}  
 
Clickable Image Button Example Output
 
Content-Type: text/html  
<HTML>  
<HEAD>  
<TITLE>html++ example application</TITLE>  
</HEAD>  
<BODY>  
<FORM ACTION="/cgi-bin/action.exe" METHOD="POST">  
Clickable image button example<P></P>  
Enter username: <INPUT TYPE="TEXT" NAME="username"><P></P>  
<INPUT TYPE="IMAGE" NAME="login" SRC="/images/login.gif"></FORM>  
</BODY>  
</HTML>  
 

ex_button3.gif  

 


©1998 DC Micro Development. All rights reserved.
No portion of this document may be c opied or reproduced without expressed written consent.
html++ is a trademark of DC Micro Development.