Skip to content

Commit 3f68763

Browse files
committed
update form-submission
1 parent a7922d8 commit 3f68763

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
<h1>Caching is fun</h1>
2+
- currently building
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
hello Flex vs grid
1+
Flex vs grid - currently building
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Actions } from "./$types";
2+
3+
export const actions: Actions = {
4+
defualt: async ({ request }) => {
5+
let form = await request.formData();
6+
console.log(form) // Form Data
7+
}
8+
};

src/routes/fullstack/concepts/form-submission/+page.svelte

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
<script>
2+
import { CodeBlock } from 'svhighlight';
3+
import { onMount } from 'svelte';
4+
5+
import 'highlight.js/styles/base16/dracula.css';
6+
import Button from '$ui/button/button.svelte';
7+
8+
let insideCode = `
9+
<form method='POST'>
10+
<div>
11+
<label for="name">Name:</label>
12+
<input type="text" id="name" name="name" required>
13+
</div>
14+
<div>
15+
<label for="email">Email:</label>
16+
<input type="email" id="email" name="email" required>
17+
</div>
18+
<button type="submit">Submit</button>
19+
</form>
20+
`;
21+
let code =
22+
`
23+
<script lang='ts'>` +
24+
`
25+
export let data;
26+
export let form;
27+
</` +
28+
`script>
29+
` +
30+
insideCode;
31+
32+
let servercode = `import type { Actions } from "./$types";
33+
34+
export const actions: Actions = {
35+
defualt: async ({ request }) => {
36+
let form = await request.formData();
37+
console.log(form) // Form Data
38+
return { success: true };
39+
}
40+
};`;
41+
</script>
42+
143
<h1>Simple Form Submission using Svelte</h1>
244
<p class="mb-2">
345
Form submission on the web typically involves sending data from a web form to a server for
@@ -18,3 +60,31 @@
1860
data to a server via an HTTP POST request, processing the data on the server, and then responding
1961
to the client's request with the appropriate content
2062
</p>
63+
<div class="not-prose">
64+
<CodeBlock
65+
language="svelte"
66+
{code}
67+
showHeader={true}
68+
showLineNumbers={false}
69+
headerText="Simple Form Submission using Svelte"
70+
/>
71+
</div>
72+
<h4>Form submission at Server Side <code>+page.server.ts</code> File</h4>
73+
<div class="not-prose">
74+
<CodeBlock
75+
language="ts"
76+
code={servercode}
77+
showHeader={true}
78+
showLineNumbers={false}
79+
headerText="Server Side Code for Form Submission using Svelte"
80+
/>
81+
</div>
82+
<div class="mt-2">
83+
6. <strong>Response from the Server</strong>: After processing the form data, the server typically
84+
sends back a response to the client (browser). This response might be a new web page, a
85+
confirmation message, or any other content determined by the server-side processing.
86+
<br />
87+
7. <strong>Displaying the Response</strong>: The browser receives the response from the server and
88+
displays it to the user. This might involve loading a new page, updating parts of the current page
89+
dynamically (using AJAX), or displaying a pop-up message.
90+
</div>

0 commit comments

Comments
 (0)