passing variables through functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jenjenut233
Forum Newbie
Posts: 7
Joined: Fri Sep 29, 2006 2:23 pm

passing variables through functions

Post by jenjenut233 »

used to be a question here.
Last edited by jenjenut233 on Sun Feb 19, 2012 10:43 pm, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
jenjenut233
Forum Newbie
Posts: 7
Joined: Fri Sep 29, 2006 2:23 pm

Post by jenjenut233 »

used to be a question here.
Last edited by jenjenut233 on Sun Feb 19, 2012 10:44 pm, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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';
}
jenjenut233
Forum Newbie
Posts: 7
Joined: Fri Sep 29, 2006 2:23 pm

Post 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.)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Don't use PHP_SELF. Use "#" or "?" instead.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
jenjenut233
Forum Newbie
Posts: 7
Joined: Fri Sep 29, 2006 2:23 pm

Post by jenjenut233 »

Thank you for your help! :-)
Last edited by jenjenut233 on Sun Feb 19, 2012 10:44 pm, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Glad we could help.
Post Reply