Top | ![]() |
![]() |
![]() |
![]() |
GHashTable * | soup_form_decode () |
GHashTable * | soup_form_decode_multipart () |
char * | soup_form_encode () |
char * | soup_form_encode_datalist () |
char * | soup_form_encode_hash () |
char * | soup_form_encode_valist () |
libsoup contains several help methods for processing HTML forms as defined by the the HTML 4.01 specification.
GHashTable *
soup_form_decode (const char *encoded_form
);
Decodes form
, which is an urlencoded dataset as defined in the
HTML 4.01 spec.
a hash
table containing the name/value pairs from encoded_form
, which you
can free with g_hash_table_destroy()
.
[element-type utf8 utf8][transfer container]
GHashTable * soup_form_decode_multipart (SoupMultipart *multipart
,const char *file_control_name
,char **filename
,char **content_type
,GBytes **file
);
Decodes the "multipart/form-data" request in multipart
; this is a
convenience method for the case when you have a single file upload
control in a form. (Or when you don't have any file upload
controls, but are still using "multipart/form-data" anyway.) Pass
the name of the file upload control in file_control_name
, and
soup_form_decode_multipart()
will extract the uploaded file data
into filename
, content_type
, and file
. All of the other form
control data will be returned (as strings, as with
soup_form_decode()
) in the returned GHashTable.
You may pass NULL
for filename
, content_type
and/or file
if you do not
care about those fields. soup_form_decode_multipart()
may also
return NULL
in those fields if the client did not provide that
information. You must free the returned filename and content-type
with g_free()
, and the returned file data with g_bytes_unref()
.
If you have a form with more than one file upload control, you will
need to decode it manually, using soup_multipart_new_from_message()
and soup_multipart_get_part()
.
multipart |
||
file_control_name |
the name of the HTML file upload control, or |
[allow-none] |
filename |
return location for the name of the uploaded file, or |
[out][allow-none] |
content_type |
return location for the MIME type of the uploaded file, or |
[out][allow-none] |
file |
return location for the uploaded file data, or |
[out][allow-none] |
a hash table containing the name/value pairs (other than
file_control_name
) from msg
, which you can free with
g_hash_table_destroy()
. On error, it will return NULL
.
[nullable][element-type utf8 utf8][transfer container]
char * soup_form_encode (const char *first_field
,...
);
Encodes the given field names and values into a value of type "application/x-www-form-urlencoded", as defined in the HTML 4.01 spec.
This method requires you to know the names of the form fields (or
at the very least, the total number of fields) at compile time; for
working with dynamic forms, use soup_form_encode_hash()
or
soup_form_encode_datalist()
.
first_field |
name of the first form field |
|
... |
value of |
char *
soup_form_encode_datalist (GData **form_data_set
);
Encodes form_data_set
into a value of type
"application/x-www-form-urlencoded", as defined in the HTML 4.01
spec. Unlike soup_form_encode_hash()
, this preserves the ordering
of the form elements, which may be required in some situations.
char *
soup_form_encode_hash (GHashTable *form_data_set
);
Encodes form_data_set
into a value of type
"application/x-www-form-urlencoded", as defined in the HTML 4.01
spec.
Note that the HTML spec states that "The control names/values are
listed in the order they appear in the document." Since this method
takes a hash table, it cannot enforce that; if you care about the
ordering of the form fields, use soup_form_encode_datalist()
.
char * soup_form_encode_valist (const char *first_field
,va_list args
);
See soup_form_encode()
. This is mostly an internal method, used by
various other methods such as soup_form_encode()
.
first_field |
name of the first form field |
|
args |
pointer to additional values, as in |