massiveattacker Posted July 11, 2006 Share Posted July 11, 2006 i apologize in advance if this sounds silly but im new to php: i want to have three forms in one php file only. i run the page and get the first form, i submit, i want the 2nd form to appear, i submit again, i want the third and final one to appear, with the others still there. the problem is, everytime i submit the 2nd time everything gets messed up and dont know how to use flags to run the code for the php form only. you understand? so imagine i have code1 code2 code3, first time i want only code1 to show up. i submit i want only code2 to show, third time i want only code3 to execute. how should i set the flags? it is killing me! Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/ Share on other sites More sharing options...
GingerRobot Posted July 11, 2006 Share Posted July 11, 2006 You could include a hidden field in your form which includes the current form. You would need to to give a default current form too...if(empty($_POST['currentform'])){$currentform=1;}else{$currentform = $_POST['currentform'];}then something like:if($currentform == 1){//show form 1}elseif($currentform == 2{//show form 2}etc.And in your form, put the following hidden field.$newform = $currentform+1;echo "<input type='hidden' name='currentform' value='$newform'>1"; Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-56077 Share on other sites More sharing options...
brown2005 Posted July 11, 2006 Share Posted July 11, 2006 what not use action=1, action=2, action=3$action = $_GET['action'];if($action == 1){}elseif($action == 2){}elseif($action == 3){}like that.. Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-56089 Share on other sites More sharing options...
kenrbnsn Posted July 11, 2006 Share Posted July 11, 2006 What I do in these cases is to have the submit button have a different value for each form, then I can do my normal test for whether a form has been submitted or not and then do a switch() on the value of the submit button:[code]<?phpif (isset($_POST['submit'])) { switch ($_POST['submit']) { case 'Submit Form 1': // or whatever is form1's submit button's value//// do work for form 1// break; case 'Submit Form 2': // or whatever is form2's submit button's value//// do work for form 2// break; case 'Submit Form 3': // or whatever is form3's submit button's value//// do work for form 3// break; }}?>[/code]No need for hidden fields or variables on the URL.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-56126 Share on other sites More sharing options...
massiveattacker Posted July 11, 2006 Author Share Posted July 11, 2006 thx everyone. without you im nothing.. Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-56188 Share on other sites More sharing options...
Daniel0 Posted July 11, 2006 Share Posted July 11, 2006 If you wan't to store more than one thing from the previous forms, you might wan't to look into [url=http://php.net/serialize]serialize[/url]. Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-56193 Share on other sites More sharing options...
massiveattacker Posted July 13, 2006 Author Share Posted July 13, 2006 guys, i think u misunderstood me. my fault. what im trying to do is: i want three dropdown menus. each one has its own submit button. all in one php file. i run the file in the browser first and i get: dropdownmenu1 [submit]i click on submiti get: dropdownmenu2 [submit]ONLY! WITHOUT dropdownmenu1i click on submit again and i get: dropdownmenu3[submit]ONLY! WITHOUT dropdownmenu1 and dropdownmenu2thats it, please help!! Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-57571 Share on other sites More sharing options...
kenrbnsn Posted July 13, 2006 Share Posted July 13, 2006 Take my answer in reply #3 and add code to display form 2 in the case for the submit of form 1, add the code to display form 3 in the case for submit of form 2.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-57577 Share on other sites More sharing options...
massiveattacker Posted July 13, 2006 Author Share Posted July 13, 2006 thx alot ken, very prompt reply, but where do i put the code of dropdownmenu1 exactly?? i only want to see it before the first time i hit submit! Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-57594 Share on other sites More sharing options...
kenrbnsn Posted July 13, 2006 Share Posted July 13, 2006 Since the switch statement only gets executed when the submit button has been pressed, you can put the code to display form 1 in statements contained in an "else" block of that "if" statement.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-57597 Share on other sites More sharing options...
massiveattacker Posted July 17, 2006 Author Share Posted July 17, 2006 great ken thx alot. it worked. i bumped into a tricky pary though, im making another file with three forms all within table cells, i want to have the first form to have 1-9 options: [form1 of 9 options] if i select 3 for example, i want to get a tree like this: [formA]_____ [formB] |____ [formB] |____ [formB]now the user can select one of the 3 formB's and select from 1 to 9 again, lets say they select 5 from formB in the middle: [formA]_____ [formB] |____ [formB]--------[formC] |____ [formB] |__ [formC] |__ [formC] |__ [formC] |__ [formC] i want to save the data in some way, can anyone help? please! Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-59512 Share on other sites More sharing options...
redarrow Posted July 17, 2006 Share Posted July 17, 2006 javascript not php ok.all the above posts were php code ok. Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-59523 Share on other sites More sharing options...
massiveattacker Posted July 17, 2006 Author Share Posted July 17, 2006 there is no way i can do that in php? Quote Link to comment https://forums.phpfreaks.com/topic/14272-3-forms/#findComment-59529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.