Jump to content

Archived

This topic is now archived and is closed to further replies.

massiveattacker

3 forms?

Recommended Posts


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!

Share this post


Link to post
Share on other sites
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";

Share this post


Link to post
Share on other sites
what not use action=1, action=2, action=3

$action = $_GET['action'];

if($action == 1)
{

}
elseif($action == 2)
{

}
elseif($action == 3)
{

}

like that..

Share this post


Link to post
Share on other sites
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]<?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;
    }
}
?>[/code]
No need for hidden fields or variables on the URL.

Ken
 

Share this post


Link to post
Share on other sites
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].

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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! 

Share this post


Link to post
Share on other sites
javascript not php ok.

all the above posts were php code ok.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.