Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-21-2005, 10:13 PM   PM User | #1
mtd
Regular Coder

 
Join Date: Jun 2003
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
mtd is an unknown quantity at this point
Form submit via link - values not saved...

Yes, this does involve some javascript, but I think the overall issue is PHP. Please correct me if I'm wrong.

I have a multipart form (all on the same page, just not displayed all at once), and I navigate between parts like so:
PHP Code:
foreach($_POST as $key => $value) {
    
$_SESSION[$pageSectionName[$_SESSION[page]]][$key] = $value;
    }

// Stores form data in Session
// FYI, $pageSectionName is an array that stores the name of
// each section, used to display the correct section

if($_POST[goTo] == '<<<'$_SESSION[page]--;
if(
$_POST[goTo] == '>>>'$_SESSION[page]++;

// REST OF CODE.....

echo '<input name="goTo" type="submit" value="<<<">';
echo 
'<input name="goTo" type="submit" value=">>>">';

// $_SESSION[page] determines what part to show (obviously
// there is more code than what is listed here, but it is not relevant
// to this issue.  If you need it, please ask, but be warned - it is quite large. 
Ok, so far, so good. Everything works. Now, I need to implement a link submit system to jump to any page, not just consecutive pages like above (although I still need the above code). So, I add:
PHP Code:
if(isset($jump)) {
    
$_SESSION[page] = $jump;
    unset(
$jump);
    }

for(
$i 1$i count($pageSectionName); $i++) {
        echo 
'<a href="order.php?jump='.$i.'" onClick="document.forms["the_form"].submit();return false;">'.$i.'</a> ';
        } 
That works, too. HOWEVER, when the links are used to navigate, any values within the form (<input> etc.) are not saved in the session. Does anyone see a way around this? Even though it is JS, there's got to be some way to save to a PHP session... I'm thinking some kind of hidden <input>, but that may be way off track?

Last edited by mtd; 06-21-2005 at 10:16 PM..
mtd is offline   Reply With Quote
Old 06-22-2005, 10:48 AM   PM User | #2
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
As far as I can see there's no reason that wouldn't work just like a standard html submit. Is the data actually there when you do:
PHP Code:
<?php 
print_r
($_POST);
?>
If it is then you should be able to assign it to your sessions without a problem and there should be no problem with previously assigned sessions being carried from one page to the next, that's what they are for after all. Try doing print_r($_SESSION); too and see if there is any session data stored, it could be that it's just not being stored how you expect and needs to be accessed differently. Also, does each page that you're posting to have session_start() at the top?
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-22-2005, 01:49 PM   PM User | #3
mtd
Regular Coder

 
Join Date: Jun 2003
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
mtd is an unknown quantity at this point
Thanks, i tried that and realized it was a JS problem - the form wasn't submitting :-(

PHP Code:
echo '<a href="order.php?jump='.$i.'" onClick="document.the_form.submit();return false;">'
is how it should have read. Now the problem is it won't go to the jump page - it returns to the current page (removing "return false;" has the opposite effect - jumps but doesn't submit . Moving my question to the JS form now!

thanks for the help in figuring out where the problem was.
mtd is offline   Reply With Quote
Old 06-22-2005, 03:31 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
quick question for you.
Can I navigate your pages with my javascript off?
My personal stats read ~43% of my visitors do not use javascript. That of course is variable, my buddy records ~87% of his visitors use javascript.
I mention this simply to point out that javascript is not a reliable way to code a website.
If its pagination your looking at, this can be done fully with php, and simply as well.
Just thought I'd point out...
Fou-Lu is offline   Reply With Quote
Old 06-22-2005, 05:13 PM   PM User | #5
mtd
Regular Coder

 
Join Date: Jun 2003
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
mtd is an unknown quantity at this point
I know how unreliable js can be - it isn't the only way to navigate, but it is an option. In short, I have two buttons ("<<<" and ">>>") that move forward and back exactly one section. That is done w/ php so anyone can use it. In addition, I have a list of numeric links (1 2 3 ... 14) that, when clicked, move to that specific section. That is done in JS. If there is a way to do that in PHP, I'm all ears! Since it is a text link, not an HTML form input, I was under the impression that JS HAD to be used to make it submit the form. am I wrong?

(Please note these are *not* seperate pages, but rather individual sections on one page. A particular section is displayed depending on the form input from the previous or next section. If they were seperate pages, I wouldn't need php or javascript - a regular <a href="###"> would do.)

Last edited by mtd; 06-22-2005 at 05:17 PM..
mtd is offline   Reply With Quote
Old 06-23-2005, 12:32 AM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Great, just making sure you had the option for javascript as off.

Now, you can easily create php to handle pagination such as this, look at the bottom of the forums here for instance, you'll have a set of links like so:
< 2 3 4 >
Its not the most simple task, but it certainly isn't the most difficult. The problem arises with your current structure. Without knowing how you generate the pagination, and exactly how it relates to each other, I cannot give you any advice with it. And it may not be worthwhile either. So long as your users can go from page to page, they will be happy. So thats what matters
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:29 AM.


Advertisement
Log in to turn off these ads.