ire4ever1190 / mike

The new and improved mikero web framework
35 stars 1 forks source link

reguarding post parameters #26

Closed AritraBanik08 closed 1 year ago

AritraBanik08 commented 1 year ago

This is my code

import
  mike,
  mustache,
  times,
  ready,
  mike/ctxhooks,
  ./http/controllers/mics,
  ./database/roomrestrictions

"/" -> get:
  let c = newContext()
  showPage("index", c)
"/" -> post:
  echo "post"
  let c = newContext()
  var
    check_in = ctx.queryParams["check-in"]
    check_out = ctx.queryParams["check-out"]
  echo check_in
  var
    startDate = parse(check_in, "ddd MMM dd yyyy")
    endDate = parse(check_out, "ddd MMM dd yyyy")

    db3 = newDatabase3()
    rooms = db3.searchAvailabilityForAllRooms(startDate, endDate)
  ctx.redirect("/choose-room")
  c["rooms"] = rooms
  showPage("choose-room", c)

servePublic("src/public", "/public")

run()

Can you tell me how to get the params from the HttpPost parameter? Thank you for this amazing framework and love your great work.

ire4ever1190 commented 1 year ago

Thanks for the kind words!

Not too sure what you mean by params from the POST? If you are talking about query parameters then what you have should be correct. I ran a simple version myself and it all seems to work but if it doesn't for you then post the error and I'll try to reproduce

If you want to get the body then you can use ctx.body which returns the request body in the form of a string. There is also ctx.json for getting the body as JsonNode

AritraBanik08 commented 1 year ago

It shows the error {"kind":"KeyError","detail":"key not found: check-in","status":400}. I want the data that the user is entering.

ire4ever1190 commented 1 year ago

Hmm ok, is the user entering the input via a form? If so then you'll probably need to use ctx.urlForm() (and then access the values from that) instead since the form might be getting sent in the body instead of via query parameters

AritraBanik08 commented 1 year ago

Thank you for your help and making such a great framework.