Hi,
Please insert the code with the formatting. I will be able to give an example of how to run it in a snippet.
https://ww.wp.xz.cn/support/topic/before-creating-a-new-topic-please-read/
Why do you share snippets, why can not you use your code in one snippet?
Because the variable is not declared, you get an empty result.
Tell me more about how you use this code and I can find a beautiful solution for you.
Best regards, Alex
Thanks for the response Alex,
Here is the post again as you asked for it. I had previous done it this way (first snippet at the top of the page and then just output the input string as a hidden variable in the form. I guess I could just as easily done this as one snippet in the form. You seem to be indicating that the value of the variables in one snippet is not available in other snippets on a page. I can deal with that in this instance but if that is the way this works I would consider that a serious limitation – especially since it worked fine that way before.
Snippet 1 is designed to take some posted data and add 3% to an amount and create an input string that goes into a form as follows:
$amt = $_POST[“cf3_field_7″];
$amt = $amt + (.03 * $amt);
$amt = round($amt,2);
$theamount = ‘<input type="hidden" name="amount" value="‘.$amt.'">’;
The second snippet simply echos $theamount as a line in a form
echo $theamount;
However when I do this the input line does not appear in the form and no amount is sent. I looked at the source code and the input statement in $theamount doesn’t appear but instead it renders <br><br>
I do not see in your case that it is necessary to divide this code into 2 snippets. But if you really want to use them in different snippets on one page, then you can do it like this.
$amt = $_POST['cf3_field_7'];
$amt = $amt + (.03 * $amt);
$amt = round($amt, 2);
global $theamount;
$theamount = '<input type="hidden" name="amount" value="' . esc_attr($amt) . '">';
[wbcr_php_snippet id="432" title="Example 1"]
global $theamount;
echo $theamount;
[wbcr_php_snippet id="433" title="Example 2"]
Best regards, Alex
-
This reply was modified 7 years, 11 months ago by
webcraftic.