Complex! Please help!
Moderator: General Moderators
Complex! Please help!
I need to write a php script to do the following:
Depending on the choice of values chosen by the user from a list, a number of pages need to be generated.
The user can select multiple item from the list, each corresponding to a page that should be generated (there are 11 of these).
The way I look at it is I need to be able to have a variable form action array.
If the user chose 3 of the items from the list, for example, the first page needs to load, then when that is submitted, the second needs to load, and so on.
This seems so complex and I'm not sure where to start, or what features of php, (or any other language for that matter) are required.
Thanks for any replies
Rick
Depending on the choice of values chosen by the user from a list, a number of pages need to be generated.
The user can select multiple item from the list, each corresponding to a page that should be generated (there are 11 of these).
The way I look at it is I need to be able to have a variable form action array.
If the user chose 3 of the items from the list, for example, the first page needs to load, then when that is submitted, the second needs to load, and so on.
This seems so complex and I'm not sure where to start, or what features of php, (or any other language for that matter) are required.
Thanks for any replies
Rick
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
seems rather simple to me, sorry. Here's the basic idea:Now generate the first page. On successful submission of that page, remove it from the session variable. Repeat until there are no more pages.
Code: Select all
<input type="checkbox" name="page[foo]" value="1" />Foo<br />
<input type="checkbox" name="page[bar]" value="1" />Bar<br />
<input type="checkbox" name="page[bif]" value="1" />Bif<br />
<input type="checkbox" name="page[baf]" value="1" />Baf<br />
<input type="checkbox" name="page[floob]" value="1" />Floob<br />Code: Select all
$expectedKeys = array('foo','bar','bif','baf','floob');
if(isset($_POST['page']) and is_array($_POST['page'])) {
$_SESSION['pages'] = array();
foreach($_POST['page'] as $key => $value) {
if(in_array($key,$expectedKeys)) {
$_SESSION['pages'][] = $key;
}
}
}- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
// build a whitelist of accepted pages to use
$expectedKeys = array('foo','bar','bif','baf','floob');
// check that the page select was in the post data before trying to use it. Verify that it is an array as well.
if(isset($_POST['page']) and is_array($_POST['page'])) {
// create/clear a session variable for the list of pages to show.
$_SESSION['pages'] = array();
// begin looping through the submitted page selection
foreach($_POST['page'] as $key => $value) {
// check that the page is in the whitelist
if(in_array($key,$expectedKeys)) {
// since the page was in the whitelist, store it into the session variable for later usage
$_SESSION['pages'][] = $key;
}
}
}Okay, pretty sure that all works. Thanks for the help so far.
I know I sound dumb, but I'm new to PHP, and as I don't know the features required for this task, it's hard to search for a solution.
Thanks again
I know I sound dumb, but I'm new to PHP, and as I don't know the features required for this task, it's hard to search for a solution.
Any hints on how to do this part? I don't mind putting some effort in, but a nudge in the right direction would be appreciated.Now generate the first page. On successful submission of that page, remove it from the session variable. Repeat until there are no more pages.
Thanks again
I am still so confused with this part.
Just to clarify, the user chooses some of the options in the list and when the page is submitted the pages corresponding to the chosen items are displayed in a sequential order. The user may not choose all of the options/pages.
Therefore I have this array, but what do I use for the form action on each page? I don't really see how this array will help me to generate the required pages.
Thanks for any help
Rick
Just to clarify, the user chooses some of the options in the list and when the page is submitted the pages corresponding to the chosen items are displayed in a sequential order. The user may not choose all of the options/pages.
Therefore I have this array, but what do I use for the form action on each page? I don't really see how this array will help me to generate the required pages.
Thanks for any help
Rick
Anybody?you check if you have pages to display left in the session variable. If pages are left, display the next.
I've been messing about with javascript to alter the form action as I cannot see a way to do it in php.
I used variables for the form action but that didn't work.
Any help would be appreciated