GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Oct-2003, 10:15
eeschumann eeschumann is offline
New Member
 
Join Date: Oct 2003
Posts: 3
eeschumann is an unknown quantity at this point

passing parameters between forms


Does anyone know how to pass Parameters from form to form...I'll explain what I'm trying to do here:
I am using 2 pages: Step1 and Step2. Iasking for users to input Sate (from a drop down menu) and a City (typed in the fieled) in the form1. I would like these paramters from the first form to appear in the form2, and then get it all back to me (info from form 1 and 2) at the end. The user would click continue button in Form 1 and then finally "send" in Form 2.
I guess I need some PHP and Java. Can anyone help?
Thanks for help!
  #2  
Old 29-Oct-2003, 15:51
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

One possible solution to your question


Hello eeschumann,

I am not certain if there is any other clever way to do this but this is what I would do if I were in your situation right now.

First, I would create the 3 following files:

functions.inc.php
PHP Code:

<?php
// FILENAME: FUNCTIONS.INC.PHP

define( 'NL', "\r\n" );
define( 'MAGIC_QUOTES_GPC', get_magic_quotes_gpc() );


function get_previous_form_values()
{
  $tmp = array();
  $stripped = '';
  $args = func_get_args();
  foreach( $args as $arg )
  {
    $stripped = stripInputData( $_POST[ $arg ] );
    $tmp[ $arg ] = htmlentities( $stripped, ENT_QUOTES );
  }
  unset( $args, $stripped );
  return $tmp;
}

function stripInputData( $input )
{
  if( MAGIC_QUOTES_GPC==TRUE )
  {
    return( stripslashes($input) );
  }
  return( $input );
}
?>


step-1.php
PHP Code:

<?php
// FILENAME: STEP-1.PHP

include_once( './functions.inc.php' );

// show the form for STEP 1
$form1 = '<form name="step1" method="post" action="step-2.php">'.NL.
         '  <p>Select STATE:<br />'.NL.
         '    <select name="state" id="state">'.NL.
         '      <option value="KE" selected="true">Kedah</option>'.NL.
         '      <option value="SE">Selangor</option>'.NL.
         '      <option value="TE">Terengganu</option>'.NL.
         '    </select></p>'.NL.
         '  <p>City:<br />'.NL.
         '    <input type="text" name="city" style="width:95px" value="" /></p>'.NL.
         '  <input type="submit" name="step1" value="Goto Step 2" />'.NL.
         '</form>'.NL;
echo $form1;
?>


step-2.php
PHP Code:

<?php
// FILENAME: STEP-2.PHP

include_once( './functions.inc.php' );

if( isset($_POST['step1']) )
{
  // the user has just submitted the form off STEP-1.PHP
  // we collect the data from FORM 1 and include it
  // in our FORM 2 as hidden form objects
  
  // first we get the previously inputted data i.e. state / city
  $step1  = get_previous_form_values( 'state', 'city' ); // function in FUNCTIONS.INC.PHP  
  // I didn't include any checking for empty / blank data off the previous form,
  // something for you to do, no doubt...
  
  // now we build and show the second form; look at the lines
  // where the hidden fields are below...
  $result = '<form name="step2" method="post" action="'.$_SERVER['PHP_SELF'].'">'.NL.
            '  <p>Your Name:<br />'.NL.
            '    <input type="text" name="name" style="width:95px" value="" /></p>'.NL.
            '  <p>How old are you?:<br />'.NL.
            '    <input type="text" name="age" style="width:95px" value="" /></p>'.NL.
            '  <input type="hidden" name="state" value="'.$step1['state'].'" />'.NL.
            '  <input type="hidden" name="city" value="'.$step1['city'].'" />'.NL.
            '  <input type="submit" name="step2" value="Process" />'.NL.
            '</form>'.NL;      
}
elseif( isset($_POST['step2']) )
{
  // this is where you process ALL the data
  // off STEP-1 and STEP-2!
  
  // DEBUG
  ///*
  $result = '<pre>'.NL.
  ob_start();
  print_r( $_POST );
  $result .= ob_get_contents();
  ob_end_clean();
  $result .= NL.'</pre>'.NL;
  //*/
}
else
{
  // the user has obviously skipped STEP-1.PHP
  die( header('location:step-1.php') );
}
echo $result;
?>


You can just copy-N-paste, then upload the 3 files and view them off a test folder in your website to see if it does what you intend to do with your script.
  #3  
Old 29-Oct-2003, 17:22
eeschumann eeschumann is offline
New Member
 
Join Date: Oct 2003
Posts: 3
eeschumann is an unknown quantity at this point
Thank you. I will try that.
  #4  
Old 30-Oct-2003, 10:58
eeschumann eeschumann is offline
New Member
 
Join Date: Oct 2003
Posts: 3
eeschumann is an unknown quantity at this point
I forgot to mention that I use Front Page 2002. Do I have to do anything for that? Also, my second form is written in Front Page, do I just add php code to it? Do I have to rename it .php instead of .htm? I am a bit confused on that.
Thank you.
  #5  
Old 31-Oct-2003, 00:12
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
It doesn't really matter if you're using FP2K to create your forms (i.e. your html code). However, whenever you need to mix php code with html, you definitely need to have the .php extension in the filenames.

There are ways to make .html parse PHP code, but seriously, you don't want to go there yet!
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache on Windows XP and passing variables Jos Elkink Apache Web Server Forum 4 21-Nov-2003 02:21
Forms in multiple windows ukrspp21 MySQL / PHP Forum 0 02-Oct-2003 11:07
[class] Generate Forms Without Using HTML! Elmseeker PHP Code Library 6 11-Mar-2003 12:05

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:33.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.