/    Sign up×
Community /Pin to ProfileBookmark

Avoid php calls on hidden html-elements?

I have some html divs with PHP-function calls inside them. I hide some of these divs with JS based on the users settings. I don’t want the PHP-functions to be called on the elements that are being hidden. Is it possible to do that?

[CODE]
<div><?php $obj->test(arg5); ?></div>
<div><?php $obj->test(arg101); ?></div>
<div><?php $obj->test(arg8); ?></div>
<div><?php $obj->test(arg26); ?></div>
[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rootApr 15.2018 — PHP is not called by the browser, it is a file rendered in the server by the PHP parser.

So if you want elements not to be used, you have to code at the server to negate them using whatever method you use to test if a conditional element will output something or not...

[CODE]<div><?php if( !empty( $obj->test(arg5) ) ) $obj->test(arg5); ?></div>
<?php if( !empty( $obj->test(arg8) ) ) echo "<div>" . $obj->test(arg8) . "</div>" . PHP_EOL; ?>
<div><?php $obj->test(arg101); ?></div>[/CODE]


one element may or may not output if its empty or not and output an empty div element, the other will output a div element or nothing depending on if the element is empty or not and the other one will always output something even if the element is empty or not.
Copy linkTweet thisAlerts:
@bbq1authorApr 15.2018 — @root#1591195 I understand. Thank you for the answer. I don't think that code would work tho because the php function return is never empty :/
Copy linkTweet thisAlerts:
@rootApr 16.2018 — They're just examples, you select the appropriate test for your needs, tests are either comparison tests like == and <, <=, >, >=, != and functions like empty(), isset() so that you can test things...
×

Success!

Help @bbq1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...