zserge / lorca

Build cross-platform modern desktop apps in Go + HTML5
MIT License
8k stars 532 forks source link

make html form data trigger another function #180

Open Juniornewxt opened 2 years ago

Juniornewxt commented 2 years ago

Hello friend, is there any way to make a page in lorka trigger another function, for example, write to an external database?

func form_html() { // Create UI with basic HTML passed via data URI

ui, err := lorca.New("data:text/html,"+url.PathEscape(`
<form method="post">
<legend>form</legend>
<fieldset>
<div>
    <label for="name">name:</label>
    <input type="text" id="name" name="name"  maxlength="18"/>
</div>
<div>
<label for="valor">email:</label>
  <input type="email" id="email" name="email"  maxlength="18"/>
</div>
</fieldset>
<div class="button">
    <button type="submit">commit</button>
</div>

`), "", 480, 320) if err != nil { log.Fatal(err)

    insert_db("name", "email")

}

defer ui.Close()
// Wait until UI window is closed
<-ui.Done()

Friends, reading the documentation, I managed to do this, but I still haven't figured out how to return the page to the beginning after submitting I click the commit button, or maybe generate a popup, is there any way to do this?