Form handling in Marko.js can be done using event handlers. Here's an example of a simple form:
<template>
<form on-submit('handleSubmit', preventDefault)>
<input type="text" name="username" placeholder="Username" />
<button type="submit">Submit</button>
</form>
</template>
<script>
module.exports = class {
handleSubmit(event) {
const formData = new FormData(event.target);
const username = formData.get('username');
console.log('Submitted username:', username);
}
};
</script>
In this example, the handleSubmit
method is called when the form is submitted, and the form data is accessed using FormData.