Jump to content

3 forms?


massiveattacker

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!
Link to comment
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";
Link to comment
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
 
Link to comment
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!!
Link to comment
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! 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.