Give the submit button of a form a value/name


#1

Hi there,

a HTML can have a name attribute, which is passed when submitting a form, e.g.

has $_POST[‘myOwnSubmit’] set when clicking the button. Is there a simple way to achieve something similar in Agile UI buttons?

Background:
I am using a “hack” to make the Autocomplete autosubmittable, see https://github.com/atk4/ui/issues/321. It submits the form on change as a normal $autocomplete_field->on(‘change’, …) does not work.

Now I am using an AutoComplete somewhere else where the “real” form submit should do something quite different, so inside the submit function I need to determine whether the AutoComplete caused the submit or clicking the button. As the AutoComplete might pass an empty value, I need to determine if the button was clicked by passing some value with it.
Maybe some small change to onClick Eventhandler? $form->buttonSave->on(‘click’, $form->js()->form(‘submit’, ‘someExtraParameter’)) ?


#2

How about simply adding hidden input field in form?


#3

Hi Imants,

can’t really figure how that helps me determine in onSubmit() where the submit was triggered from.

Actually I have another Idea for a workaround with the supernice, but complicated AutoCompletes: A Form inside a Form, only for the AutoComplete. something like:

$form = $app->add(['Form']); //The normal Form
$form_ac = $form->layout->add(['Form']); //Form only for the AutoComplete
$ac = $form_ac->addField('add_guest', ['AutoComplete', ....include custom JS onChange form submit....]);

$form_ac->onSubmit(
     ...handle what a change of Autocomplete should do
);

I will give it a try later, seems a sensible way to work around the flaws of AutoComplete field.


#4

something like this:

$button->on(‘click’, [ $field->jsInput()->val(1); $form->js()->form(‘submit’); ]);

But yes, knowing which form submitted the button is obviously very useful.


#5

This is getting nasty… I thought that a form exclusively for the autocomplete inside the actual form would be the most sensible way to go. But: HTML forbids nested forms…


#6

Finally made it by restructuring the page and adding an extra form only for the AutoComplete :slight_smile: