...

View Full Version : Form submit via link - values not saved...



mtd
06-21-2005, 10:13 PM
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:
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:
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?

delinear
06-22-2005, 10:48 AM
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
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?

mtd
06-22-2005, 01:49 PM
Thanks, i tried that and realized it was a JS problem - the form wasn't submitting :-(


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.

Fou-Lu
06-22-2005, 03:31 PM
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...

mtd
06-22-2005, 05:13 PM
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.)

Fou-Lu
06-23-2005, 12:32 AM
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 ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum