www.webdeveloper.com
Results 1 to 4 of 4

Thread: Form processing, preserving POST variables

  1. #1
    Join Date
    Aug 2007
    Location
    Washington
    Posts
    219

    Form processing, preserving POST variables

    The layout for my form validation is thus:

    PHP Code:
        if(array_key_exists('_preview',$_POST)) {
            
    // If validate_form() returns errors, pass them to show_form()
            
    if($form_errors validate_form()) {
                
    show_form($form_errors);
            } else {
            
    // The submitted data is valid, so process it
                
    preview_form();
            }
        }
        if(
    array_key_exists('_submit',$_POST)){
            
    process_form();
        }
        else {
            
    // The form wasn't submitted or BACK was selected from preview, so display
            
    show_form();
        } 
    The showform() has two buttons at the end. A preview button and a reset. If the preview button is pressed, then it validates the form, then creates a preview. The preview then gives you two buttons, to submit the info or go back and edit it again. When hit either of these buttons, the $_POST data is deleted, so I was wondering if there was I way I could keep it, without having to reassign it as a session variable. Because then, I would have to edit my show_form() to be able to handle $_post and $_session. Would I have to make hidden fields on the preview page?

    Any ideas? Much thanks.

  2. #2
    Join Date
    May 2007
    Location
    Tamalanrea
    Posts
    33
    Why not assign the value back to the form again? (put the preview page on the same page with the form). So, your fields of form will be :

    PHP Code:
    <input type="text" name="fname" value="<?=$_POST["fname"]?>">
    When users want to edit, all they have to do is editing the form again and if they are satisfied with the content, they can submit it.

  3. #3
    Join Date
    Aug 2007
    Location
    Washington
    Posts
    219
    So something more like this:

    PHP Code:
        if(array_key_exists('_submit',$_POST)) {
            
    // If validate_form() returns errors, pass them to show_form()
            
    if($form_errors validate_form()) {
                
    show_form($form_errors);
            } else {
            
    // The submitted data is valid, so process it
                
    process();
            }
        }
        else {
            
    // The form wasn't submitted or preview was selected, so display
            
    show_form();
        } 
    In the show_form function I would have an if(array_key_exists('_preview',$_POST)), which would display all the data if everything displayed correctly. Is this right?

    But then I then the form only validates when the submit button is pressed and not the preview button. Oh btw, my buttons are named "_submit" and "_preview"

    Edit: I've been looking around, but I've found nothing; is there a class that could this all for me? Because it sucks doing this for each form.
    Last edited by bejitto101; 12-05-2008 at 06:20 PM.

  4. #4
    thanks a lot.... thanks for your information... very much useful for me.... keep on posting...:-)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles