Proper way to write one PHP file to do many "steps" for mmbr
Posted: Fri Feb 27, 2009 5:50 pm
Hello Everyone-
I am working on a site where users can create an account, log in, and store various information about their friends and contacts (phone numbers, names, etc). This is a small example. The site stores lots of information and there are currently 50+ php files that I've created to make it all work.
My question is, I've seen some sites that call the same file to do multiple phases of a process. Example. You are directed to addcontact.php to add a contact. It prints out "Step 1 - Enter the contact's name". They click ok. It takes them to addcontact.php AGAIN (using a form POST) and the page says "Step 2 - Enter phone number", etc. etc, until you've reached the "Save" phase.
The way that I always used to code was to actually build different php files for each step. addcontact.php, addcontact_step2.php, addcontact_step3.php, addcontact_addtodatabase.php, etc.
I saw some websites that basically have one php file that "does it all". It knows what step you are on and formats the page accordingly. I am wondering how this is accomplished? (Like what is the best way). I played around with it, and I got it to work, but it just feels like I did it long handed or wrong. I test for isset for some POST variables at the beginning of the PHP file. If I find certain ones, I set a variable named $step to an appropriate value, and then based on that value print out the proper page. I'm using input type=hidden in order to keep posting the information from the previous step(s) to the form, over and over.
Can anyone point me in the right direction here. I do not even know what I am trying to do is called so my searches have lead me no where. I'm really wanting to reuse code for adding/editing, and there are a couple of spots where there is a bit of information that is important and relevant to the rest of the page, so I want to take them through a Step 1, Step 2, Save type process ... All using the same php file.
Thanks for any suggestions in advance!!
I am working on a site where users can create an account, log in, and store various information about their friends and contacts (phone numbers, names, etc). This is a small example. The site stores lots of information and there are currently 50+ php files that I've created to make it all work.
My question is, I've seen some sites that call the same file to do multiple phases of a process. Example. You are directed to addcontact.php to add a contact. It prints out "Step 1 - Enter the contact's name". They click ok. It takes them to addcontact.php AGAIN (using a form POST) and the page says "Step 2 - Enter phone number", etc. etc, until you've reached the "Save" phase.
The way that I always used to code was to actually build different php files for each step. addcontact.php, addcontact_step2.php, addcontact_step3.php, addcontact_addtodatabase.php, etc.
I saw some websites that basically have one php file that "does it all". It knows what step you are on and formats the page accordingly. I am wondering how this is accomplished? (Like what is the best way). I played around with it, and I got it to work, but it just feels like I did it long handed or wrong. I test for isset for some POST variables at the beginning of the PHP file. If I find certain ones, I set a variable named $step to an appropriate value, and then based on that value print out the proper page. I'm using input type=hidden in order to keep posting the information from the previous step(s) to the form, over and over.
Can anyone point me in the right direction here. I do not even know what I am trying to do is called so my searches have lead me no where. I'm really wanting to reuse code for adding/editing, and there are a couple of spots where there is a bit of information that is important and relevant to the rest of the page, so I want to take them through a Step 1, Step 2, Save type process ... All using the same php file.
Thanks for any suggestions in advance!!