diff --git a/s1/src/routes/faculty/signup/+page.server.ts b/s1/src/routes/faculty/signup/+page.server.ts index e69de29..f752bf6 100644 --- a/s1/src/routes/faculty/signup/+page.server.ts +++ b/s1/src/routes/faculty/signup/+page.server.ts @@ -0,0 +1,30 @@ +import type { Actions } from "@sveltejs/kit"; +import { redirect } from '@sveltejs/kit'; + +export const actions: Actions = { + default: async ({ request }) => { + // console.log(request.json()); + + var endpoint = "http://localhost:8082/controller/faculty/create"; + var data = await request.formData(); + + var res = await fetch(endpoint.concat("?fn=", String(data.get('fn')), "&ln=", String(data.get('ln')), "&em=", String(data.get('em')), "&pw=", String(data.get('pw'))), { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + // body: JSON.stringify(data), + }) + var data1 = await res.json(); + + if (res.ok) { + // Successful fetch + throw redirect(303, '/'); // Redirect to success page + } else { + // Handle error + return { + error: data1.msg, + }; + } + }, +} \ No newline at end of file