jeudi 14 avril 2016

Spray - Parsing forms with checkboxes

I am setting up a simple API part of which accepts POST requests via form submission. The form requires the user to select one or more checkboxes all sharing the same name e.g.

<form>
  <input type='text' name='textval'>
  <input type='checkbox' name='cbox' value='val1'> Value 1
  <input type='checkbox' name='cbox' value='val2'> Value 2
  <button type='submit'>Submit</button>
</form>

I am attempting to handle the request in Spray like so:

path("mypath") {
  post {
    formFields('textval, 'cbox) { (textval, cbox) =>
      // Now what?
    }
  }
}

I cannot find documentation in the Spray Docs on how to handle such inputs. In fact, this seemed to be an issue that has now been fixed, but I am unsure how to handle this form field with the Spray API




Aucun commentaire:

Enregistrer un commentaire