Page 1 of 1
Complex! Please help!
Posted: Fri Feb 10, 2006 10:20 am
by scs3rd
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
Posted: Fri Feb 10, 2006 10:27 am
by John Cartwright
What do you have so far?
Posted: Fri Feb 10, 2006 10:32 am
by feyd
seems rather simple to me, sorry. Here's the basic idea:
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;
}
}
}
Now generate the first page. On successful submission of that page, remove it from the session variable. Repeat until there are no more pages.
Posted: Fri Feb 10, 2006 10:52 am
by scs3rd
Thanks for the quick reply.
Would you be able to explain the code step-by-step, not really sure what it is doing.
I already have a list array of the entries chosen by the user.
Thanks for your time, much appreciated
Posted: Fri Feb 10, 2006 11:02 am
by feyd
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;
}
}
}
Posted: Fri Feb 10, 2006 11:07 am
by scs3rd
Thanks!
Posted: Sat Feb 11, 2006 5:51 am
by scs3rd
What are $key and $value and what are their purpose?
Thanks
Rick
Posted: Sat Feb 11, 2006 9:28 am
by feyd
Posted: Sat Feb 11, 2006 10:32 am
by scs3rd
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.
Now generate the first page. On successful submission of that page, remove it from the session variable. Repeat until there are no more pages.
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.
Thanks again
Posted: Sat Feb 11, 2006 10:43 am
by feyd
Posted: Sun Feb 12, 2006 6:57 am
by scs3rd
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
Posted: Sun Feb 12, 2006 11:41 am
by feyd
you check if you have pages to display left in the session variable. If pages are left, display the next.
Posted: Wed Feb 15, 2006 2:05 pm
by scs3rd
I've been struggling with this for days now and not moved forward.
If anybody wishes to be kind enough to post any code, it would be much appreciated, as I am getting too frustrated with this task.
Thanks
Posted: Fri Feb 17, 2006 8:30 am
by scs3rd
you check if you have pages to display left in the session variable. If pages are left, display the next.
Anybody?
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