PostValues returns all the parsed form data from POST, PATCH, or PUT body parameters based on a "name" as a string slice. The default form's memory maximum size is 32MB, it can be changed by the `iris#WithPostMaxMemory` configurator at main configuration passed on `app.Run`'s second argument. In a
(name string)
| 1892 | // Look ErrEmptyForm, ErrNotFound and ErrEmptyFormField respectfully. |
| 1893 | // See `PostValueMany` method too. |
| 1894 | func (ctx *Context) PostValues(name string) ([]string, error) { |
| 1895 | _, ok := ctx.form() |
| 1896 | if !ok { |
| 1897 | if !ctx.app.ConfigurationReadOnly().GetFireEmptyFormError() { |
| 1898 | return nil, nil |
| 1899 | } |
| 1900 | |
| 1901 | return nil, ErrEmptyForm // empty form. |
| 1902 | } |
| 1903 | |
| 1904 | values, ok := ctx.request.PostForm[name] |
| 1905 | if !ok { |
| 1906 | return nil, ErrNotFound // field does not exist |
| 1907 | } |
| 1908 | |
| 1909 | if len(values) == 0 || |
| 1910 | // Fast check for its first empty value (see below). |
| 1911 | strings.TrimSpace(values[0]) == "" { |
| 1912 | return nil, fmt.Errorf("%w: %s", ErrEmptyFormField, name) |
| 1913 | } |
| 1914 | |
| 1915 | for _, value := range values { |
| 1916 | if value == "" { // if at least one empty value, then perform the strip from the beginning. |
| 1917 | result := make([]string, 0, len(values)) |
| 1918 | for _, value := range values { |
| 1919 | if strings.TrimSpace(value) != "" { |
| 1920 | result = append(result, value) // we store the value as it is, not space-trimmed. |
| 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | if len(result) == 0 { |
| 1925 | return nil, fmt.Errorf("%w: %s", ErrEmptyFormField, name) |
| 1926 | } |
| 1927 | |
| 1928 | return result, nil |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | return values, nil |
| 1933 | } |
| 1934 | |
| 1935 | // PostValueMany is like `PostValues` method, it returns the post data of a given key. |
| 1936 | // In addition to `PostValues` though, the returned value is a single string |
no test coverage detected