#Fresh form post, how to render the same page with new data?

5 messages · Page 1 of 1 (latest)

summer whale
#

can you use the query?

#

my form doesn't have any sensitive information (passwords, bank details) so that's what i personally use myself

rocky condor
#

I'm not sure I understand?

Maybe I also explained it poorly.

Here's an example of trying to post something to the handler and returning it to the same page.

async POST(req, ctx) {
    let form = await req.formData();
    let email = form.get("email")?.toString();
    console.log(email);
    return ctx.render({ email });
  },

This works. I can see the email being logged.

Then we have a simple page component,

(props: PageProps<Data>) => {
  console.log("data", props.data);
  let email = props.data?.email ?? "";
  console.log("email", email);

  return (
    <main>
      <h1>Log in</h1>

      <form method="POST">
        <input type="email" name="email" />

        <button>Log in</button>
      </form>

      <p>{{ email }}</p>
    </main>
  );
};

This also logs email server side, but client side it's not rendered. There's no email being added to the screen.

summer whale
#

you know what are URL queries, right?

#

<p>{{ email }}</p>
why the double brackets? won't that return an object "{email: email}"?