0

I am using two forms on an HTML page hosted via GCDWebServer. I have the first form setup like this...

<form name=\"vendorInput\" method=\"post\" enctype=\"application/x-www-form-urlencoded\">
<input type=submit value='Add Vendor' action=\"/\">

and the second form setup like this...

<form name=\"vendorInput\" method=\"post\" enctype=\"application/x-www-form-urlencoded\">
<input type=submit value='Add Item' action=\"/\">

I can't find any documentation that provides support for this; and any action string I type other than / causes the HTML request to break. Is there a way to parse different actions for form submit buttons in GCDWebServer?

Scott
  • 1,154
  • 1
  • 12
  • 25

1 Answers1

0

You just need to have the action be a different path for each form and then implement a GCDWebServer handler for each path:

[webServer addHandlerForMethod:@"POST"
                          path:@"/path1"
                  requestClass:[GCDWebServerURLEncodedFormRequest class]
                  processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {

  // Do something with form data i.e. [[(GCDWebServerURLEncodedFormRequest*)request arguments]
  return [GCDWebServerDataResponse responseWithHTML:@"<html><body>OK</body></html>"];

}];

[webServer addHandlerForMethod:@"POST"
                          path:@"/path2"
                  requestClass:[GCDWebServerURLEncodedFormRequest class]
                  processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {

  // Do something with form data i.e. [[(GCDWebServerURLEncodedFormRequest*)request arguments]
  return [GCDWebServerDataResponse responseWithHTML:@"<html><body>OK</body></html>"];

}];

See https://github.com/swisspol/GCDWebServer#advanced-example-2-implementing-forms for an example.

Pol
  • 3,848
  • 1
  • 38
  • 55