Script UI turns one PHP script into an internal tool. The script has no route and no form handling, and still the page reacts to every input. This post goes through one click slowly, because everything else in the library follows from it.
The tool is the smallest one there is:
<?php // tools/hello.php
// Hello
// My first tool.
use function Runio\ScriptUi\{title, text, button, success};
title('Hello');
$name = text('Your name');
if (button('Greet') && $name !== '') {
success('Hello, ' . $name . '.');
}
One click, step by step

Say the user typed "Ava" into the field and presses Greet.
- The browser sends the whole form. Not a message about this one button: every input goes, every time. Here that is three fields:
your-namewith what was typed,_clickwith the button that was pressed, and_token, a long random text that the page carries. - Script UI asks three questions before a line of your script runs: who is asking, may they open this tool, and is the form ours? The token answers the third one. A no ends the request there.
- Your script runs from the top.
title('Hello')puts the title on the new page. text('Your name')puts the field on the page and returns'Ava'. That is the value the browser has just sent, with the blanks at both ends taken away.button('Greet')puts the button on the page and returnstrue, because this is the run that its click started.- The
ifis true, sosuccess()puts the green message on the page. - The script is at its end, and Script UI sends the new page back.
- The browser swaps the content. The page is not loaded again, and the keyboard focus stays where it was.
The first page of the website plays these eight steps, and you can use the small page there yourself.
Now change the name
Type "Omar" into the field and press Enter. The same eight steps happen, with one difference: the form has no _click, because nobody pressed the button. So button('Greet') returns false, the line inside the if does not run, and the new page has no greeting.
That surprises people once. Then it is the part they like: a button is true in one run only. You keep no flag, and you reset none.
What follows from it
The order of the code is the order of the page. What you call first stands at the top. An if around a part decides whether it is there, and an early return ends the page.
That goes for the button too. The condition of the example is button('Greet') && $name !== '', in that order. Turned around, PHP would not call button() while the name is empty. A function that is not called draws nothing, so the button would be gone until somebody typed a name.
Work that changes data belongs behind a button. The script also runs when somebody only changes a filter, and when a page refreshes by itself. Inside if (button(...)) your code runs once for each click:
if (button('Refund', confirm: 'Refund order ' . $order['id'] . '?')) {
$refunds->create($order['id']); // runs once, after a click and a yes
success('Refunded.');
}
With confirm: the button asks first, and it returns true only after the user answered yes to exactly that question.
The script keeps nothing between two runs. A variable is gone when the run ends, as in every PHP request. What the user entered comes back through the input functions, and everything else comes from your database.
When the script runs again
- The user chooses an option, ticks a box, picks a date or changes a number: at once.
- The user types into a text field: when they press Enter or leave the field.
- The user types into the search box of a table: after a short pause in the typing.
- The user presses a button: at once, and
button()is true in that run. - Nobody does anything on a page that calls
refresh(30): every 30 seconds, while the page is in view.
What it costs
Every interaction is a request that runs the whole script. For a tool with a query and a table that is cheap, and you do not think about it. But a script that needs two seconds makes every click wait two seconds.
Work that takes long does not belong in the script at all. A worker does it, and the tool starts it and shows how far it is with progress() and refresh(). The fifth tutorial builds such a tool.
The model is not mine. Streamlit made it popular in Python. It fits internal tools well: they are small, few people use them at the same time, and whoever writes them wants to think about the task and not about the page.
In the next post I walk through a tool that changes data, a refund tool in 40 lines, and put it behind a login.
Author Amer Malik Mohammed
Full-Stack Developer with 2+ years of experience in object-oriented PHP development (Symfony), JavaScript and MySQL. Specialized in e-commerce solutions (Shopware 5/6), REST API development and process automation in agile teams.
Contact author