Cgic concise tutorial 4: Get the parameter values in the request

Source: Internet
Author: User

How can we extract the values in a form when submitting a form?
For example, the following form:

<Form action = "cgi-bin/out. cgi" method = "Post">
<Input type = "text" name = "name"/>
<Input type = "text" name = "Number"/>
<Input type = "Submit" value = "Submit"/>
</Form>

When an out. cgi request is received, extract the values in the input box "name" and input box "number. And it must be valid no matter whether the action in form is get or post.

The following sample code is provided:

Download: Test. c
  1. # Include <stdio. h>
  2. # Include "cgic. H"
  3. # Include <string. h>
  4. # Include <stdlib. h>
  5. Int cgimain (){
  6. Char name [241];
  7. Char number [2, 241];
  8. Cgiheadercontenttype ("text/html ");
  9. Fprintf (cgiout, "<HTML>
  10. Fprintf (cgiout, "<title> my CGI </title>
  11. Fprintf (cgiout, "<body> ");
  12. Cgiformstring ("name", name, 241 );
  13. Cgiformstring ("Number", number, 241 );
  14. Fprintf (cgiout, "
  15. Fprintf (cgiout, "
  16. Fprintf (cgiout, "</body>/N ");
  17. Fprintf (cgiout, "
  18. Return 0;
  19. }

As shown in the code above, rows 13th and 14th obtain the value of the input box.

Obtains the input parameter values in cgic. cgiformstring is one of the most commonly used functions.
Cgiformstringnonewlines is used to remove line breaks (if you enter characters in a textarea );
Cgiformstringspaceneeded is used to test the length of the input value. Based on this, you can precisely allocate the buffer as needed.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.