#React component | onSubmit not working
23 messages ยท Page 1 of 1 (latest)
anyone a idea?
Hey, are you using a client directive in your component?
No. this is my complete code.
https://hastebin.skyra.pw/iwepecugod.ts
Oh I mean in the Astro component you're using this component in
No
---
/* Import components */
import RegisterForm from "../../components/auth/RegisterComponent.jsx";
/* Import api classes */
import Auth from "../../api/Auth.js";
---
<!DOCTYPE html>
<html lang="de">
<head>
<!-- Meta tags -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Website title -->
<title>YourDevelopers - Auth</title>
<link rel="icon" type="image/svg+xml" href="/img/logo-icon.svg" />
<!-- Public css files -->
<link rel="stylesheet" href="/css/root.css">
</head>
<body>
<RegisterForm/>
</body>
</html>
Ah you should use one then ๐
Otherwise no javascript is sent to the browser, only the html of your form
Have a look at this https://docs.astro.build/en/reference/directives-reference/#client-directives
That would explain the problem
client:load or client:only is a good choice for a form as far as I can tell right?
Yeah any would be a good choice
client:load will include your form in the html, but client:only won't, from that you can pick a choice
Now it works, but the JavaScript code should be processed on the server side for security reasons. Is it sufficient to outsource the server-side code?
Just tested it. Unfortunately it is always executed on the client side, is there a solution?
What do you want executed on the clientside and what on the server exactly?
I would like my registration data which is entered to be sent to the server and validated there and compared with the database and the client side should then receive the information whether everything is correct or not.
Ah I see, you could use an api route to handle that, and make a fetch call to it on the client
I'm going to try that out. Thank you for your help and that you also help beginners who do not yet have so much knowledge of Server Side in JS
I had a look at the docs, seems like an endpoint via express would be a good option. I will implement this in the next few days. This should work
Thanks