XF 2.0 Save without reloading/redirection

CMTV

Well-known member
Hi!

I have a basic entity Add\Edit admin template with simple form in it:

HTML:
<!-- TITLE AND PAGE ACTIONS -->

<xf:form action="{{ link('phpc-criteria/save', $criterion) }}" ajax="true" class="block">
    <div class="block-container">
  
        <!-- FORM FIELDS HERE -->

        <xf:submitrow sticky="true" icon="save" class="js-submitButton" data-ajax-redirect="{{ $criterion.isInsert() }}">
            <xf:html>
                <xf:button type="submit" name="exit" icon="save">{{ phrase('save_and_exit') }}</xf:button>
            </xf:html>
        </xf:submitrow>
    </div>
    <xf:redirect />
</xf:form>

How can I save entity and show "Your changes has been saved" flash message without page reload/redirection?

In other words, how can I do save process just like when editing existing templates in ACP?

I tried to add class="js-submitButton" and data-ajax-redirect attributes but they do not work. The page is reloading after clicking "Save" or pressing "Ctrl + S".
 
Last edited:
I think you may need an extra xf:form attribute: data-skip-overlay-redirect="true"

This is what the report_create template uses, where the form opens in an overlay.

EDIT: Unless this is for an Admin template? Then I'm not sure... :confused:
 
Last edited:
Nope. It is not working. The page is reloading.

My form is not showing in overlay. It is a standalone page (just like template_edit one)

UPD: Yes it is an Admin template.
 
Ok. I found the problem.

The values for data-ajax-redirect must be 1 or 0. {{ false }} is not working and the attribute does not even appear in html markup.

So the correct value for that attribute in my case is:
Code:
data-ajax-redirect="{{ $criterion.isInsert() ? '1' : '0' }}"
 
Top Bottom