# How to create and use gui elements (e.g. button) with XWiki API

**URL:** <https://forum.xwiki.org/t/how-to-create-and-use-gui-elements-e-g-button-with-xwiki-api/3936>\
**Category:** Help / Discuss\
**Tags:** script, velocity, page-editing\
**Created:** [November 15, 2018, 3:23pm UTC](https://forum.xwiki.org/t/how-to-create-and-use-gui-elements-e-g-button-with-xwiki-api/3936 "2018-11-15T15:23:31Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Valentin](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/v/f19dbf/32.png) [@Valentin](https://forum.xwiki.org/u/Valentin)\
**Post date:** [November 28, 2018, 3:29pm UTC](https://forum.xwiki.org/t/how-to-create-and-use-gui-elements-e-g-button-with-xwiki-api/3936/2 "2018-11-28T15:29:48Z")

</div>

I now solved it, thanks to the help of @vmassol.

**TL;DR**  
This is how I did it:

- build a form with HMTL+Javascript
- make a HTTP request to a wiki page, URL can be built in JS
- create a wiki page which parses the URL, retrieves  
document reference & values
- store the values in the XObject of the referenced document.

**Long explanation:**  
You can simply use a HTML macro to build a HTML form, as you would do it anywhere.  
Then you either add a Javascript Extension (JSX) to the page, or you write your code directly in `<script>...</script>` tags. Then you can invoke JS code from HTML, e.g. when a button is klicked.  
This JS code then retrieves the values from the HTML form fields and puts together an URL with parameters.  
Then you create a XmlHttpRequest (or whatever) and send the HTTP request. It is going to a wiki page which parses it and retrieves the reference of the target document as well as the field names and values for the XObject you want to set.

Of course, I tried to make things as generic as possible, to make it extendable, but sometimes you still have to handle each field specifically, e.g. in a special HTML input.

The XWiki software doesn’t show very many things on the surface, but when you dig deeper you find out that it’s quite consistent and well thought-through even at details.

Thanks for such a great open source project!

Cheers

---

_[View the full topic](https://forum.xwiki.org/t/how-to-create-and-use-gui-elements-e-g-button-with-xwiki-api/3936)._
