Validate form submit if triggered by onchange="this.form.submit()"

Hello everyone,

I have difficulties validating if a form is submitted. The functionality should be like: I select an item from the select form and it immediately triggers the submit via javascript this.form.submit(). The script below works fine if I remove get('submit') from the if statement. I got that snippet part from Email contact form | Kirby CMS, except my form must be validated on the exact same page instead of another one as the select element is a category filter.

Is the problem that the submit is triggered by javascript because get(β€˜submit’) never gets executed? Wondering what the problem here is. I also got things like this to work before fine with raw PHP and HTML just fine but want it to work the intended kirby way.
I tried POST and GET on form’s method attribute but with no difference in result. In HTML5 form elements can work just fine with no attributes.

Thank you.

if($kirby->request()->is('get') && get('submit')) {
      <select class="form-select" aria-label="Projektfilterung" name="categories" onchange="this.form.submit()">

This would come from the submit input in the example form, so does not apply to your use case and you have to remove it.

1 Like