Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    mtd
    mtd is offline
    Regular Coder
    Join Date
    Jun 2003
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #3
    mtd
    mtd is offline
    Regular Coder
    Join Date
    Jun 2003
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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...

  • #5
    mtd
    mtd is offline
    Regular Coder
    Join Date
    Jun 2003
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •