SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Keeping Info in a Form

    Hey,

    So I have a form where it redirects you to a error page if you missed a field.

    The problem with this is, that it clears all the fields that you did type in. So I want it to carry these fields over to the error page, even if some are missing.

    Here's some of the code in my form to help you see how I'm doing this...

    Code:
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$sex = $_POST['sex'];
    	$security = $_POST['security'];
    	$comments = $_POST['comments'];
    Code:
    	if (!empty($errors)) {
    		header("Location: feedback_error.php?errors=" . urlencode(implode(", ", $errors)));
    		exit;
    	}
    I know how this can be achieved, but I can't wrap my head around how I might get it to work.

    Basically I can check if they entered something other then the default value and pass that through in the url. Then read it back on the error page from the url. I'm just not sure how I could achieve this.

    I'm going to go and try to figure it out, but if anyone can help that'd be awesome.

    Thanks,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  2. #2
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    Hi there, my 1st post here.
    About your problem, you can put your html to point to the same page. Here you just check if something was submitted.
    PHP Code:
    <?php
    //stuff ...

    if( isset($_POST[name]) ){
    // check for stuff here
    }else{
    ?>
    <!--put html here-->

    <form action=""...
    <input name="name" value="<?=$_POST['name']?>" />
    ....etc
    <!-- end html :) -->
    <?php
    }
    ?>
    Please note the value="<?=$_POST['name']?>"
    Last edited by andr; Oct 7, 2007 at 17:18. Reason: errored explanation

  3. #3
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rather than redirecting on error, why not just submit to the same page then just store into $error. Then you still have all submitted fields that you can put into the form fields' value attribute
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  4. #4
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, triexa is right. You can add an $error variable and then juggle with it
    I hope it helps. If you still have trouble tell us.

  5. #5
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies guys.

    Thats a good point, I throw in a new div on top when theres an error stating what error happened. I guess I just can't figure out how to keep that on the same page.

    Thanks,
    Mario

    I'm basically trying to do this...

    1. Check if the name field is not blank or the value within does not equal Name.

    2. If it passes the first test, pass the value contained in $name to the url on the error page. So then I could just pull it from there and fill the field in.

    Here's the code I'm using but it doesn't seem to be working.

    Code:
    if (!empty($name)) {
    		$saved_name = $name;
    	}
    Code:
    	if (!empty($errors)) {
    		header("Location: feedback_error.php?errors=" . urlencode(implode(", ", $errors))) . "&name=" . urlencode($saved_name);
    		exit;
    	}
    But it's not working. Is it because $name is not a global variable and can't be called from outside of the function?

    Thanks,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  6. #6
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    before if (!empty($name)) {
    put this: $name = $_POST['name'];

  7. #7
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have all that just above that code...

    Code:
    	$headersep = (!isset($check) || (check == 0))?"\r\n":"\n";
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$sex = $_POST['sex'];
    	$security = $_POST['security'];
    	$comments = $_POST['comments'];
    	$http_referer = getenv("HTTP_REFERER");
    any other ideas?

    Thanks,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  8. #8
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also before that you should check if( isset($_POST['name']))

  9. #9
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe it'll help if you guys see the form, you can find it here...

    http://zenit.senecac.on.ca/~dma322_073b13/Basic_Form
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  10. #10
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ooww simultaneous posting...
    you can call that function with the parameters $name, $sex, etc. or you can make those vars globals

  11. #11
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    name will always be set, cause it has a default value of Name in it.

    So i can use...

    Code:
    if (!empty($name) || ($name != Name)) {
    		$saved_name = $name;
    	}
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  12. #12
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, do you have something like $name = $_POST['name']?


    As for "same page" something like:

    Code:
    <?
    if ($_POST) {
        if ($_POST['name'] != 'Kaitlyn')
            $error = 'You did not enter a good enough name';
    }
    
    if (isset($error)) {
        echo '<div style="color:#FF000; font-weight:bold">' . $error . '</div>';
    }
    ?>
    <form action="this_script.php" method="post">
    Your name: <input type="text" name="name" value="<?=$_POST['name']?>" />
    <input type="submit" value="Submit" />
    </form>
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  13. #13
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet triexa, I'm going to try to use that code right now to cur off the error page.

    Thanks

    Anyone on the other problem? :-P
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  14. #14
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ethics View Post
    name will always be set, cause it has a default value of Name in it.

    So i can use...

    Code:
    if (!empty($name) || ($name != Name)) {
    		$saved_name = $name;
    	}
    Name needs to be in quotes..

    Code:
    $name != 'Name'
    or
    Code:
    $name != "Name"
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  15. #15
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Thanks for trying guys,

    Let me try to make the question super simple to understand cause we've gotten a bit off track.

    Code:
    if (!empty($errors)) {
    		header("Location: feedback_error.php?errors=" . urlencode(implode(", ", $errors)));
    		exit;
    	}
    How can I add more to this line, so that more shows up in the browser window.

    I tried...

    Code:
    if (!empty($errors)) {
    		header("Location: feedback_error.php?errors=" . urlencode(implode(", ", $errors)) . "&name=");
    		exit;
    	}
    But that doesn't add it to the url.

    Any ideas?

    Thanks,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  16. #16
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand why you've gone back to the redirect on error, and then try to pass all the data back in the URL...
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter


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
  •