SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 34 of 34
  1. #26
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Location
    Australia, Victoria
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont see why people use sessions to send the errors over when the form is processed what is wrong with.

    PHP Code:
    <?php

        
    if ( $_POST['submit'] )
        {
            
    //do error stuff here
        
    }
        else
        {
            
    //show form here
            
    echo '<form method="post" action="#add_news">';
            echo 
    '</form>';
        }

    ?>
    That way it kind of does the error checking on the fly ?

  2. #27
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess mainly because:

    - we're trying to implement Redirect After Post in order to have a more user-friendly forms, without those re-post warnings,
    - we're using different URLs for form editing end form posting, which means you have to go back to the "edit form" page if you discover user errors on the "post form" page.

  3. #28
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dbevfat
    - we're trying to implement Redirect After Post in order to have a more user-friendly forms, without those re-post warnings,
    That's precisely the reason I don't use the single-method, cascade approach... the re-post nightmare. Using a session allows me to worry less.

  4. #29
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Location
    Australia, Victoria
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I kind of understand how to redirect after post im just abit confused how to implement it, is it just sending the action to a new page and do the calculations on the new page.

    Then what would you do if you had to go back to the form, redirect to the new form so its 2 redirects all together which seems kind of tedious and ugly to me.

    Could i just get abit of an insight on how to set it up.

  5. #30
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You just don't redirect; Instead you redisplay the form as is so you remove the problem, to my mind anyways.

    If you need to pre-fill the form with data then you pull that data out of storage, rather than depend on the data being present as you would expect via said redirection.

    But I agree, I too don't like it anymore either

  6. #31
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There seems to be some confusion on how to use sessions and forms. Here's how I do forms in http+html applications.

    1) User GET your page.
    2) If a session exists for the form, goto 5.
    3) Else two arrays are created in session. One for errors, and one for form state.
    4) State is initiated with default values.
    5) The displayhandler is called.
    6) The displayhandler displays errors and displays a form with the data from state.
    6b) Flush the errors array
    7) User POST form to page.
    8) State is updated from $_POST.
    9) State is validated. Any errors are written to errors.
    10) If the state is valid, the validhandler is called.
    11) Else send a redirect to this page. The redirect automatically makes the browser issue a new GET, goto 1.
    12) The validhandler processes the valid form and destroys the session.
    13) After validhandler, redirect to somewhere else in your application. (Or just to the same page - goto 1)

    If you want a less persisting strategy, you can change step 2 and 11 to :
    2) If a session exists for the form and if a magic param is passed in $_GET (For example isset($_GET['retain'])), goto 5.
    ...
    11) Else send a redirect to this page with the magic param on the querystring. (Eg. mypage.php?retain) The redirect automatically makes the browser issue a new GET, goto 1.

    Hope that clarifies things a bit.
    Last edited by kyberfabrikken; Sep 21, 2006 at 23:31. Reason: Just realized that I missed a step

  7. #32
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Qc
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for this step by step approach. This clarify a lot of things for me.

    I'm not a beginner to PHP, but sometimes my brain just won't let me think about that kind of solutions.

    Regards,

  8. #33
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How much data is too much though if using sessions for large forms?

  9. #34
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you need to redirect if there are errors? If there are errors I am assuming have a user double submit is not a problem because you are not inserting anything into the database until there are no errors.


Bookmarks

Posting Permissions

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