Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
nsIFormSubmission.h File Reference
#include "nsISupports.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


class  nsIFormSubmission
 Interface for form submissions; encompasses the function to call to submit as well as the form submission name/value pairs. More...




nsresult GetSubmissionFromForm (nsGenericHTMLElement *aForm, nsPresContext *aPresContext, nsIFormSubmission **aFormSubmission)
 Get a submission object based on attributes in the form (ENCTYPE and METHOD)

Define Documentation

{ 0x7ee38e3a, 0x1dd2, 0x11b2, \
  {0x89, 0x6f, 0xab, 0x28, 0x03, 0x96, 0x25, 0xa9} }

Definition at line 53 of file nsIFormSubmission.h.

Function Documentation

nsresult GetSubmissionFromForm ( nsGenericHTMLElement aForm,
nsPresContext aPresContext,
nsIFormSubmission **  aFormSubmission 

Get a submission object based on attributes in the form (ENCTYPE and METHOD)

aFormthe form to get a submission object based on
aPresContextthe presentation context
aFormSubmissionthe form submission object (out param)

Definition at line 1135 of file nsFormSubmission.cpp.

  nsresult rv = NS_OK;

  // Get all the information necessary to encode the form data

  // Get BIDI options
  PRUint8 ctrlsModAtSubmit = 0;
  PRUint32 bidiOptions = aPresContext->GetBidi();
  ctrlsModAtSubmit = GET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions);

  // Get encoding type (default: urlencoded)
  nsFormSubmission::GetEnumAttr(aForm, nsHTMLAtoms::enctype, &enctype);

  // Get method (default: GET)
  PRInt32 method = NS_FORM_METHOD_GET;
  nsFormSubmission::GetEnumAttr(aForm, nsHTMLAtoms::method, &method);

  // Get charset
  nsCAutoString charset;
  nsFormSubmission::GetSubmitCharset(aForm, ctrlsModAtSubmit, charset);

  // Get unicode encoder
  nsCOMPtr<nsISaveAsCharset> encoder;
  nsFormSubmission::GetEncoder(aForm, aPresContext, charset,

  // Get form processor
  nsCOMPtr<nsIFormProcessor> formProcessor =
    do_GetService(kFormProcessorCID, &rv);

  // Choose encoder
  // If enctype=multipart/form-data and method=post, do multipart
  // Else do URL encoded
  // NOTE:
  // The rule used to be, if enctype=multipart/form-data, do multipart
  // Else do URL encoded
  if (method == NS_FORM_METHOD_POST &&
      enctype == NS_FORM_ENCTYPE_MULTIPART) {
    *aFormSubmission = new nsFSMultipartFormData(charset, encoder,
                                                 formProcessor, bidiOptions);
  } else if (method == NS_FORM_METHOD_POST &&
             enctype == NS_FORM_ENCTYPE_TEXTPLAIN) {
    *aFormSubmission = new nsFSTextPlain(charset, encoder,
                                         formProcessor, bidiOptions);
  } else {
    if (enctype == NS_FORM_ENCTYPE_MULTIPART ||
        enctype == NS_FORM_ENCTYPE_TEXTPLAIN) {
      nsAutoString enctypeStr;
      aForm->GetAttr(kNameSpaceID_None, nsHTMLAtoms::enctype, enctypeStr);
      SendJSWarning(aForm, "ForgotPostWarning", PromiseFlatString(enctypeStr));
    *aFormSubmission = new nsFSURLEncoded(charset, encoder,
                                          formProcessor, bidiOptions, method);

  // This ASSUMES that all encodings above inherit from nsFormSubmission, which
  // they currently do.  If that changes, change this too.
  NS_STATIC_CAST(nsFormSubmission*, *aFormSubmission)->Init();

  return NS_OK;

Here is the call graph for this function:

Here is the caller graph for this function: