rh-penguin Posted March 27, 2007 Share Posted March 27, 2007 hi, I've got 3 pieces of code in one page(including the forms). Every single piece of code has its own submit button. What i want to do is once the 1st code/form has bin filled in and the submit button has bin pressed the 2nd piece of code/form appears. But how can i tell php to go to a specific code because its not in a variable or an array or anything like that. Theres multiple if and else statments and so on. So my question is: how can i assign the code into different parts/sections? Thanks! Link to comment https://forums.phpfreaks.com/topic/44486-howto-separate-code-into-different-sections-to-execute-at-different-times/ Share on other sites More sharing options...
r-it Posted March 27, 2007 Share Posted March 27, 2007 set a hidden field on each form and that will tell u which code to process, and have a unique value in the hidden field like code 1 is gonna have the value 1 ens. eg: $type = $_POST[hidden]; then use a case statement or an if/else to determine which code to process Link to comment https://forums.phpfreaks.com/topic/44486-howto-separate-code-into-different-sections-to-execute-at-different-times/#findComment-216067 Share on other sites More sharing options...
rh-penguin Posted March 27, 2007 Author Share Posted March 27, 2007 Sorry i dont really understand. Say i have a code like this <?php $bandwith = $_POST['bandwith']; $a = $_POST['a']; if( is_numeric( $bandwith ) && is_numeric( $a ) ) { if ( $a <= 3000) { $a = 24; $result = $bandwith / $a; } elseif ( $a <= 4000) { $a = 32; $result = $bandwith / $a; } else { $result = $bandwith / $a; $a = floor($a); } } echo("The result: <u><b>$result</b></u>"); ?> How would i apply the hidden field? by $type what do you mean? Link to comment https://forums.phpfreaks.com/topic/44486-howto-separate-code-into-different-sections-to-execute-at-different-times/#findComment-216213 Share on other sites More sharing options...
yzerman Posted March 27, 2007 Share Posted March 27, 2007 ok, if I understand correctly, you have 3 forms in one php form. To do this you would have to execute it like this <?php //check to see which form(s) have been completed, if it has, move on to the next form if (!isset($_POST['submit1']) && !isset($_POST['submit2']) && !isset($_POST['submit3'])) { //if none of the forms have been submitted, echo the first form echo 'form1'; } else { // one of the forms has just been submitted, lets see which one it was, and echo the next form if (isset($_POST['submit1'])) { // first form complete, echo the second form echo 'form2'; } if (isset($_POST['submit2'])) { //second form complete, echo the third echo 'form3' } } ?> Link to comment https://forums.phpfreaks.com/topic/44486-howto-separate-code-into-different-sections-to-execute-at-different-times/#findComment-216228 Share on other sites More sharing options...
rh-penguin Posted March 27, 2007 Author Share Posted March 27, 2007 ok, if I understand correctly, you have 3 forms in one php form. To do this you would have to execute it like this <?php //check to see which form(s) have been completed, if it has, move on to the next form if (!isset($_POST['submit1']) && !isset($_POST['submit2']) && !isset($_POST['submit3'])) { //if none of the forms have been submitted, echo the first form echo 'form1'; } else { // one of the forms has just been submitted, lets see which one it was, and echo the next form if (isset($_POST['submit1'])) { // first form complete, echo the second form echo 'form2'; } if (isset($_POST['submit2'])) { //second form complete, echo the third echo 'form3' } } ?> But how would i make/assign the form1, form2 and form3? How do i take the above code that i posted and assign it to say form1? Link to comment https://forums.phpfreaks.com/topic/44486-howto-separate-code-into-different-sections-to-execute-at-different-times/#findComment-216319 Share on other sites More sharing options...
rh-penguin Posted March 28, 2007 Author Share Posted March 28, 2007 Anyone? :-\ Link to comment https://forums.phpfreaks.com/topic/44486-howto-separate-code-into-different-sections-to-execute-at-different-times/#findComment-216735 Share on other sites More sharing options...
trq Posted March 28, 2007 Share Posted March 28, 2007 Wrap each section of code in a function then execute each function as required. A quick example. <?php function a() { echo "this is a<br />"; } function b() { echo "this is b<br />"; } function c() { echo "this is c<br />"; } if (isset($_GET['function'])) { switch ($_GET['function']) { case "a" : a(); break; case "b" : b(); break; case "c" : c(); break; } } echo "<a href='?function=a'>get a</a><br />"; echo "<a href='?function=b'>get b</a><br />"; echo "<a href='?function=c'>get c</a><br />"; ?> Link to comment https://forums.phpfreaks.com/topic/44486-howto-separate-code-into-different-sections-to-execute-at-different-times/#findComment-216740 Share on other sites More sharing options...
rh-penguin Posted March 29, 2007 Author Share Posted March 29, 2007 Thanks for that. Link to comment https://forums.phpfreaks.com/topic/44486-howto-separate-code-into-different-sections-to-execute-at-different-times/#findComment-217750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.