# button

Source: https://zotonic.com/docs/1384/button

URI: https://zotonic.com/id/1384

Language: en



Makes a button with an action attached.

This is an easy way to make a button and attach one or more actions or a postback.

For example:

```django
{% button text="Click me" action={alert text="Hello Word!"} %}
```

This show a button with the text “Click me”. When clicked it will trigger the <a href="/id/doc_template_action_action_alert" class="doc-reference doc-reference-action"><code>action#alert</code></a> action, showing an alert message with the text “Hello World!”.

Another example:

```django
{% button text="Postback" postback={my_postback arg1=1 arg2=2} %}
```

When clicked it will call the `event/2` function in the controller that served the page. The function will be called as:

```erlang
event(#postback{message={mypostback, [{arg1,1}, {arg2,2}]},
    trigger=TriggerId, target=TargetId}, Context)
```

Where TriggerId and TargetId are both the HTML id of the button.

`button` accepts the following arguments:

| Argument   | Description                                                                      | Example                      |
| ---------- | -------------------------------------------------------------------------------- | ---------------------------- |
| `text`     | The text on the button, defaults to “Submit”                                     | `text=”click me”`            |
| `postback` | An event sent to the delegate or the resource serving the page.                  | `postback=”hello”`           |
| `tag`      | The type of HTML tag that will be created. Defaults to “button”.                 | `tag=”a”`                    |
| `delegate` | The name of the erlang module to be called for handling the postback.            | `delegate=”myresource”`      |
| `action`   | The action to be triggered when the button is clicked. There can be more than one action argument. | `action={show target=”msg”}` |
| `id`       | Id of the button.                                                                | `id=#submit`                 |
| `class`    | The css class of the button. This argument can be repeated to add multiple classes. | `class=”submit”`             |
| `style`    | The css style of the button.                                                     | `style=”color: #fc0”`        |
| `tabindex` | The value for the tabindex property.                                             | `tabindex=1`                 |
| `type`     | The type attribute of the button.                                                | `type=”submit”`              |
| `title`    | The title attribute of the button.                                               | `title=”click to submit”`    |
| `disabled` | The disabled attribute of the button, set to true or false. When the button is disabled then the class “disabled” is added to the class list. | `disabled=true`              |
| `href`     | The href attribute of the button if tag “a” is used. Defaults to “#”.            | `href=”/foobar”`             |

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1384?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1384?language=en>)
