Ways to write if statements in DMX tags?

I want to have the if statement include an AND for the condition. Is this possible?

Do the DMX tags only understand the Ternary operator or can you write normal if statements also?

<dmx-serverconnect id="confirm" url="dmxConnect/api/Security/checkUserConfirmed.php" dmx-on:success="confirm.data.confirmed == 0 && <?php echo $_SERVER["PHP_SELF"] ?> != '/page-confirm.php' ? browser1.goto('confirm') : ''"></dmx-serverconnect>

Did you try it? Did it work?

It did not work. I’m not sure it can handle ANDs in the condition. I think I may need to build more specific Server Actions that will return a boolean.

Well yes actually you should declare everything in the ServerAction and also at AppConnect. I created something similar some time ago. If I remember where I used it I will send you a sample.

Thank you!

This is a problem I’m encountering though and I need to have a condition that checks which page the Action is on. PHP_SELF is returning the Server Action file name, not the page file name.

You can use ‘&&’ etc. in ternary operators in Wappler. Eg you can do some simple tests such as:
{{2&gt;1 && 4&gt;3 ?'result1':'result2'}}
or
{{(2&gt;1 && 4&gt;10) || 4&gt;3 ?'result1':'result2'}}

I asked about this recently. I think the ternary operator is the only option but there wasn’t an official reply.

Try using $_SERVER[“REQUEST_URI”], may work better, also remember, if I recall correctly, php_self is routing aware

I have tried PHP_SELF, REQUEST_URI, and SCRIPT_NAME. All of them return slightly different references to the Server Action file, not the page it’s running on.

This is what is returned when using a set value in Server Action, but I would hope this would show the page it’s on, not the Server action file name.
/dmxConnect/api/Security/userDetails.php?

Here’s my action

Here is my code in my header.php server include to display the page/file name
<p dmx-text="userDetails.data.currentPage"></p>

Here’s is what shows on my home page and all of pages that use the header include.

image

Taking this a step further. If I add the Server variables directly to the header include file then these
<p dmx-text="userDetails.data.currentPage"></p>
<p><?php echo $_SERVER['PHP_SELF'] ?></p>
<p><?php echo $_SERVER['SCRIPT_NAME'] ?></p>
<p><?php echo $_SERVER['REQUEST_URI'] ?></p>

Produce these. This was taken from the ‘projects.php’ page with route ‘projects’
/dmxConnect/api/Security/userDetails.php?
/projects.php
/projects.php
/projects

So REQUEST_URI is what I want to use, but using it in the Server Action is pointless.

To close the loop. I found a way to accomplish my need. I had to add the $_Server Variable directly to the page, instead of in the Server Connect Action. Additionally, the php code needs to be in between single quotes.

The below code checks the value of the “Confirm” field on the current user’s record. If it is 0 and the current page is not the “confirm” page, then we redirect to the confirm page.

<dmx-serverconnect id="userDetails1" url="dmxConnect/api/Security/userDetails.php" dmx-on:success=" userDetails.data.getUserDetails[0].confirmed==0 && '<?php echo $_SERVER['REQUEST_URI'] ?>' != '/confirm' ? browser1.goto('confirm') : ''"></dmx-serverconnect>

1 Like