Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatically modify page conditions #2297

Open
nestordedios opened this issue Feb 19, 2025 · 1 comment
Open

Programmatically modify page conditions #2297

nestordedios opened this issue Feb 19, 2025 · 1 comment
Labels

Comments

@nestordedios
Copy link

Question

I'm looking for a way to programmatically modify existing page conditions or set page conditions.

My use case is that I have a multi-page form where visibility of certain pages depend on the value of a Craft CMS global field. I’d like to update the condition dynamically via PHP or JavaScript when the form is being processed or rendered.

This is my condition in the UI

Image

and I want to be able to set 2100 with the value I fill in in a global/entry field.

Is there an existing way to modify page conditions programmatically?

Additional context

No response

@engram-design
Copy link
Member

It's a tiny bit cumbersome, but should be possible:

{% set pageConditions = form.pages[1].settings.pageConditions %}

{% set pageCondition = pageConditions.conditions[0] %}
{% set pageCondition = pageCondition | merge({ value: '2200' }) %}

{% set pageConditions = pageConditions | merge({ conditions: [pageCondition] }) %}

{% do form.setPageSettings(1, {
    pageConditions: pageConditions,
}) %}

With 1 being the index of the page you want to modify. It's a bit overcomplicated due to the lack of handling with Twig and setting nested variable values, so sorry for all the merging rubbish! Maybe one day we'll be able to do:

{% do form.pages[1].settings.pageConditions.conditions[0].value = '2200' %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants