• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

BUG PHP snippet – submit and navigation

shq

New member
Messages
1
Likes
0
Points
1
#1
I have created two php snippets:
PHP snippet [1] (page 1)
PHP snippet [2] (page 2)

How the code is working and my question:
  • From page 1 i submit form1 and navigate to page 2 like this:
echo do_shortcode('[wbcr_snippet id="2"]'); //call page2
  • When page 2 is loaded new html for this page is built, it contains form2
  • From page 2 I submit the form2
  • I expect the php code of the page 2 to be executed(php code on top of page 2 inside <?php ?>), but instead page 1 php code is executed
  • Question: Is this how its suppose to work or a bug...
    • a) why is page2 phpcode not executed on submit from page2, when form2 is located in same snippet?
    • b) when i submit form2 from page2, why is the page navigated back to page1?

PHP snippet [1] (page 1) – code
<?php
if(isset($_POST['test_post_2'])){
echo 'php code page1: button from page 2 submit' . '<br>';
}
if(isset($_POST['test_post_1'])){
echo 'php code page1: button from page 1 submit' . '<br>';
$style_page1 = "style='display:none;'";
echo do_shortcode('[wbcr_snippet id="2"]'); //call page2
}
?>
<html>
<head>
</head>
<body>
<form action="" name="form1" method="post" >
<div class="page1" id="page1" <?php echo $style_page1;?>>
<h2>Page 1</h2>
Email:
<input type="text" name="1_email">
<br>
<input type="submit" name="test_post_1" value="submit page 1" />
</div>
</form>
</body>
</html>

PHP snippet [2] (page 2) - code
<?php
if(isset($_POST['test_post_2'])){
echo 'php code page2: button from page 2 submit' . '<br>';
echo 'we want to stay on page 2';
}
if(isset($_POST['test_post_1'])){
echo 'php code page2: button from page 1 submit' . '<br>';
}
?>
<html>
<head>
</head>
<body>
<form action="" name="form2" method="post" >
<div class="page2" id="page2" <?php echo $style_page2;?>>
<h2>Page 2</h2>
Email:
<input type="text" name="2_email"> <br>
<input type="submit" name="test_post_2" value="submit page 2" />
</div>
</form>
</body>
</html>
 

Temyk

Support team
Staff member
Messages
263
Likes
19
Points
18
#2
Hello.

a) Because the form 2 processing code only fires when form 1 is submitted. Therefore-never
And the php code of the second snippet will work only in the place where you called it with do_shortcode.

b) Because you're still on page 1.
The do_shortcode function does not perform navigation, it includes a snippet in the text of the current page.