Hi everyone,
This might be a simple question, but I don't know what are the keywords to search for the solution.
Generally speaking, I would like a form element (i.e. submit button) to access a variable declared in PHP. The scenario is, there is a submit button element in the form, which will be hided/shown by altering the "class" value according to some logic in PHP. The logic is done in "Custom Code" action in "OnLoad" event. In "Custom Code" action (in "OnLoad" event):
The code of "Submit" button in the form:
Unfortunately, the "Submit" button cannot get the value of "$class". It is also not working if I move the entire code snippet from "Custom Code" into "Submit" button, since "Submit" button also cannot access "$recordFound". I know JavaScript could be an option. However, I want to avoid using JS as much as possible. Are there any workable solutions without JS?
Thank you in advance for any suggestions!
This might be a simple question, but I don't know what are the keywords to search for the solution.
Generally speaking, I would like a form element (i.e. submit button) to access a variable declared in PHP. The scenario is, there is a submit button element in the form, which will be hided/shown by altering the "class" value according to some logic in PHP. The logic is done in "Custom Code" action in "OnLoad" event. In "Custom Code" action (in "OnLoad" event):
<?php
$class = "";
if($recordFound)
$class="show";
else
$class="hide";
?>
The code of "Submit" button in the form:
<input type="submit" class="<?php echo $class; ?>" />
Unfortunately, the "Submit" button cannot get the value of "$class". It is also not working if I move the entire code snippet from "Custom Code" into "Submit" button, since "Submit" button also cannot access "$recordFound". I know JavaScript could be an option. However, I want to avoid using JS as much as possible. Are there any workable solutions without JS?
Thank you in advance for any suggestions!
Hi flyeminent,
This should work OK but you prbably need to declare $class as global in both places.
Bob
This should work OK but you prbably need to declare $class as global in both places.
<?php
global $class;
$class = "";
if($recordFound) {
$class="show";
} else {
$class="hide";
}
?>
<input type="submit" class="<?php global $class; echo $class; ?>" />
Bob
Ok, I will try that global variable tonight.
Just a follow-up question, if I declare "$class" as global variable, will the variable be visible to other forms (including form element, form actions etc.)?
Just a follow-up question, if I declare "$class" as global variable, will the variable be visible to other forms (including form element, form actions etc.)?
Hi GreyHead,
I just tried your suggestion but it was not working. I pasted my code for your investigation. I really appreciate if you could work out this problem without introducing JavaScript.
Above my "Submit Button", I use a "Custom Element" to try to output the variable value from PHP. The code is
In form's "OnLoad" event, I use a "Custom Code" action to compute the logic, the code is
Unfortunately, the custom element displayed "button class = " on the front end, which means it could not read the "$add_button_class" variable even it is declared as global.
I just tried your suggestion but it was not working. I pasted my code for your investigation. I really appreciate if you could work out this problem without introducing JavaScript.
Above my "Submit Button", I use a "Custom Element" to try to output the variable value from PHP. The code is
<p><?php
global $add_button_class;
echo "button class = ".$add_button_class;
?></p>
In form's "OnLoad" event, I use a "Custom Code" action to compute the logic, the code is
<?php
global $add_button_class;
$found= //Get from database
if($found) {
$add_button_class = "hide";
}
else {
$add_button_class = "show";
}
?>
Unfortunately, the custom element displayed "button class = " on the front end, which means it could not read the "$add_button_class" variable even it is declared as global.
Hi flyeminent ,
Do you have the Custom Code action before the Show HTML action in the OnLoad event?
Bob
Do you have the Custom Code action before the Show HTML action in the OnLoad event?
Bob
Hello GreyHead,
Yes, the "Custom Code" action is before the "Show html" action. The "Load JS" action after "Custom Code" action can access the global (or non global) php variable, but it seems that "Show html" action is blind of the global php variables.😢
Yes, the "Custom Code" action is before the "Show html" action. The "Load JS" action after "Custom Code" action can access the global (or non global) php variable, but it seems that "Show html" action is blind of the global php variables.😢
This topic is locked and no more replies can be posted.