0

I´m working on a JForm with some list fields. As the fields have a cascading relationship (and I did not want to work with AJAX at this time) I submit the form, whenever the selection of one of the list fields changes as @sharky described here by adding the onchange attribute to the field defintion:

<field
    name="access"
    type="accesslevel"
    label="JOPTION_FILTER_ACCESS"
    description="JOPTION_FILTER_ACCESS_DESC"
    onchange="this.form.submit();"
    >
    <option value="">JOPTION_SELECT_ACCESS</option>
</field>

Normally When a form is submitted by clicking a button, the "value" of the button is included in the post message, so it is easy to indentify what caused the submission and handle the data appropriately.

However in this case when the form was submitted because the selection of one of the list fields changed, the post message only contains the submitted values, but no indication about which element caused the submission. However I would need this information to handle the submission appropriately.

What would be the best way to mark/figure out which list field caused the submission?

Thanks, W.

1 Answer 1

1

Create a hidden field in your form:

<field
    name="example"
    type="hidden"
/>

Before submitting the form, populate this field with the ID or name of the field used to submit the form:

<field
    name="access"
    type="accesslevel"
    label="JOPTION_FILTER_ACCESS"
    description="JOPTION_FILTER_ACCESS_DESC"
    onchange="document.getElementById('filter_example').value = this.id; this.form.submit();"
    >
    <option value="">JOPTION_SELECT_ACCESS</option>
</field>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.