# Halaman Form

Update file src/helper/path.js&#x20;

```javascript
export const PATH_URL = {
  BASE: "/",
  ABOUT: "/tentang-kami",
  USER_LIST: "/admin/users",
  USER_CREATE: "/admin/users/add"
}
```

Buat file src/routes/UserAdd.svelte

```javascript
<script>
  import Navigation from "../components/Navigation.svelte"
  import Input from "../components/Input.svelte"
  import Button from "../components/Button.svelte" 
  import { notifications } from '../helper/toast'
  import { PATH_URL } from "../helper/path"
  import { navigate } from "svelte-routing"
  import { HOST_URL } from '../env'

  const state = {
    email: "",
    password: "",
    name: "",
    age: "" 
  }
  let isLoading = false

  const handleInput = (e) => {
    const { value, name } = e.target
    state[name] = value
  }

  const createUser = async () => {
    const url = HOST_URL + "/users"
    var xmlHttp = new XMLHttpRequest()
    xmlHttp.open("POST", url, true)
    xmlHttp.setRequestHeader("Content-type", "application/json")
    xmlHttp.send(JSON.stringify(state))
    
  }

  const onCreate = async () => {
    try {
      isLoading = true
      await createUser()
      isLoading = false

      navigate(PATH_URL.USER_LIST, { replace: true })
    } catch(e) {
      isLoading = false;
      notifications.danger(e.message)
    }
  };


</script>
<Navigation/>

<h1>Tambah User</h1>
<main>
  <form on:submit|preventDefault={onCreate}>
    <Input label="Email" name="email" on:input={handleInput} bind:value={state.email} placeholder="username" type="email" required/>
    <Input label="Password" name="password" on:input={handleInput} bind:value={state.password} placeholder="password" type="password" required/>
    <Input label="Name" name="name" on:input={handleInput} bind:value={state.name} placeholder="name" type="text" required/>
    <Input label="Age" name="age" on:input={handleInput} bind:value={state.age} placeholder="age" type="number" required/>
    <Button isLoading={isLoading}>Login</Button>
  </form>
</main>
```

Update file src/App.svelte

```javascript
<script>
	import { Router, Route } from "svelte-routing"
	import About from "./routes/About.svelte"
	import Home from "./routes/Home.svelte"
	import { PATH_URL } from "./helper/path"
	import UserList from "./routes/UserList.svelte"
	import ProtectedRoute from "./ProtectedRoute.svelte"
	import Toast from "./components/Toast.svelte"
	import UserAdd from "./routes/UserAdd.svelte"
</script>

<Router>
	<Route path={PATH_URL.BASE} component={Home}/>
	<Route path={PATH_URL.ABOUT} component={About}/>
	<ProtectedRoute path={PATH_URL.USER_LIST} component={UserList} />
	<ProtectedRoute path={PATH_URL.USER_CREATE} component={UserAdd} />
</Router>
<Toast/>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seri-belajar-pemrograman.rijalasepnugroho.com/svelte/halaman-form.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
