Jump to content


Photo

3 forms?


  • Please log in to reply
12 replies to this topic

#1 massiveattacker

massiveattacker
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 11 July 2006 - 09:54 AM


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!

#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 11 July 2006 - 10:02 AM

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";


#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 11 July 2006 - 10:23 AM

what not use action=1, action=2, action=3

$action = $_GET['action'];

if($action == 1)
{

}
elseif($action == 2)
{

}
elseif($action == 3)
{

}

like that..

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 11 July 2006 - 11:53 AM

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:
<?php
if (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;
    }
}
?>
No need for hidden fields or variables on the URL.

Ken
 

#5 massiveattacker

massiveattacker
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 11 July 2006 - 01:48 PM

thx everyone. without you im nothing..

#6 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 11 July 2006 - 01:52 PM

If you wan't to store more than one thing from the previous forms, you might wan't to look into serialize.

#7 massiveattacker

massiveattacker
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 July 2006 - 08:33 PM

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 submit

i get:

dropdownmenu2
[submit]

ONLY! WITHOUT dropdownmenu1

i click on submit again and i get:

dropdownmenu3
[submit]

ONLY! WITHOUT dropdownmenu1 and  dropdownmenu2

thats it, please help!!


#8 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 July 2006 - 08:44 PM

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

#9 massiveattacker

massiveattacker
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 July 2006 - 09:11 PM

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!

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 July 2006 - 09:15 PM

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

#11 massiveattacker

massiveattacker
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 July 2006 - 05:36 PM


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! 



#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 July 2006 - 05:54 PM

javascript not php ok.

all the above posts were php code ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 massiveattacker

massiveattacker
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 July 2006 - 06:02 PM

there is no way i can do that in php?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users