Page 1 of 1

passing variables through functions

Posted: Wed Jan 31, 2007 1:41 pm
by jenjenut233
used to be a question here.

Posted: Wed Jan 31, 2007 1:46 pm
by RobertGonzalez
Can you maybe post your form code as well as how you are checking for processed forms? Right now it looks like your code shows that your functions do absolutely nothing, so there is no real way for us to help you.

Posted: Wed Jan 31, 2007 1:54 pm
by jenjenut233
used to be a question here.

Posted: Wed Jan 31, 2007 2:00 pm
by RobertGonzalez
Have you thought of maybe including them? Say something along the lines of...

Form1.php

Code: Select all

<form name="quote" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   <input type="radio" name="logo" value="Logo for Web" />
   <input type="radio" name="logo" value="Logo for Print" />
   <input type="radio" name="logo" value="Identity Package" />


   <input type="radio" name="web" value="5 Page Website" />
   <input type="radio" name="web" value="10 Page Website" />
   <input type="radio" name="web" value="20 Page Website" />
                <input onclick="setDisplay('5','block');" type="checkbox" name="web2" value="Additional Pages" />
   <input type="text" size="2" name="additional_pages" />

   <div align="center">
      <input type="submit" name="check_quote" value="View Total" />
      <input type="reset" name="reset" value="Clear Form" />
   </div>
</form>

Code: Select all

function form1() {
  include 'form1.php';
}

Posted: Wed Jan 31, 2007 2:08 pm
by jenjenut233
Yes I have. But if the includes are called within a function, then that still doesn't help with my problem of the variables being passed from the first section to the last. The form variables are all being set within the if (isset(check_quote)) block... so when the script gets to the else if (isset(send)) block, it has rid itself of the local variables within the first and won't pull them into the latter unless they are passed somehow (typically through return values or global variables - none of which are working for me in this case.)

Posted: Wed Jan 31, 2007 2:13 pm
by feyd
Don't use PHP_SELF. Use "#" or "?" instead.

Posted: Wed Jan 31, 2007 2:20 pm
by RobertGonzalez
Might I suggest either sessions or hidden form values?

What you have is a stepped process of form completion, so after step 1, the user is sent to step 2 where information from step 1 was used. Step 2 repeats the process to step 3.

Maintaining state between the steps is either going to be done with carrying the $_POST array data through with hidden form fields or by pushing data by the query string using the $_GET array or by sessions.

Posted: Wed Jan 31, 2007 3:07 pm
by jenjenut233
Thank you for your help! :-)

Posted: Wed Jan 31, 2007 3:11 pm
by RobertGonzalez
Glad we could help.