MCPcopy Index your code
hub / github.com/labstack/echo / FormValue

Function FormValue

binder_generic.go:213–234  ·  view source on GitHub ↗

FormValue extracts and parses a single form value from the request by key. It returns the typed value and an error if binding fails. Returns ErrNonExistentKey if parameter not found. Empty String Handling: If the form field exists but has an empty value, the zero value of type T is returned with

(c *Context, key string, opts ...any)

Source from the content-addressed store, hash-verified

211//
212// See ParseValue for supported types and options
213func FormValue[T any](c *Context, key string, opts ...any) (T, error) {
214 formValues, err := c.FormValues()
215 if err != nil {
216 var zero T
217 return zero, fmt.Errorf("failed to parse form value, key: %s, err: %w", key, err)
218 }
219 values, ok := formValues[key]
220 if !ok {
221 var zero T
222 return zero, ErrNonExistentKey
223 }
224 if len(values) == 0 {
225 var zero T
226 return zero, nil
227 }
228 value := values[0]
229 v, err := ParseValue[T](value, opts...)
230 if err != nil {
231 return v, NewBindingError(key, []string{value}, "form value", err)
232 }
233 return v, nil
234}
235
236// FormValueOr extracts and parses a single form value from the request by key.
237// Returns defaultValue if the parameter is not found or has an empty value.

Callers 1

Calls 2

NewBindingErrorFunction · 0.85
FormValuesMethod · 0.80

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…