Roman Sandler
Software Engineer at Fiverr
07/06/2023
import { createServerAction$, redirect } from "solid-start/server";
function EnrollmentPage() {
const [enrolling, { Form }] = createServerAction$(async (form: FormData, { request }) => {
const subject = form.get("subject") as string;
const user = await getLoggedInUser(request);
await prisma.enrollment.create({
data: {
userId: user.id,
subject
}
});
return redirect("/enrollment");
});
return (
<Form>
<input type="hidden" name="subject" value="Defense against the Dark Arts" />
<button type="submit" disabled={enrolling.pending}>
Enroll
</button>
</Form>
);
}
import { component$ } from '@builder.io/qwik';
import { routeAction$, Form } from '@builder.io/qwik-city';
export const useAddUser = routeAction$(async (user) => {
const userID = await db.users.add(user);
return {
success: true,
userID,
};
});
export default component$(() => {
const action = useAddUser();
return (
<Form action={action}>
<input name="name" />
<button type="submit">Add user</button>
{action.value?.success && <p>User added successfully</p>}
</Form>
);
});
import { cookies } from 'next/headers';
// Server action defined inside a Server Component
export default function AddToCart({ productId }) {
async function addItem(data) {
'use server';
const cartId = cookies().get('cartId')?.value;
await saveToDb({ cartId, data });
}
return (
<form action={addItem}>
<button type="submit">Add to Cart</button>
</form>
);
}
<?php
$name=$_POST["name"];//receiving name field value in $name variable
$password=$_POST["password"];//receiving password field value in $password variable
echo "Welcome: $name, your password is: $password";
?>
<form action="login.php" method="post">
<table>
<tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>
<tr><td>Password:</td><td> <input type="password" name="password"/></td></tr>
<tr><td colspan="2"><input type="submit" value="login"/> </td></tr>
</table>
</form>
By Roman Sandler