+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: Return All Variables To Form Page On Error

  1. #1
    Join Date
    Apr 2004
    Posts
    5

    Lightbulb Return All Variables To Form Page On Error

    Hello,

    I wanted to use the form page as the $bad_url and return the submitted variables to the form page so that the user did not have to fill them in again. Here is the code I changed in formmail.php to do this:


    --[ FIND ]--
    if (!empty($bad_url))
    {
    if (strpos($bad_url,'?') === false)
    $bad_url .= '?error='.urlencode("$error_mesg");
    else
    $bad_url .= '&error='.urlencode("$error_mesg");
    Redirect($bad_url);
    }
    --[ REPLACE WITH ]--
    if (!empty($bad_url))
    {
    while( list($index,$key) = each($_POST) ) {
    $query_string.='&'.$index.'='.urlencode($key);
    }
    if (strpos($bad_url,'?') === false)
    $bad_url .= '?error='.urlencode("$error_mesg").$query_string;
    else
    $bad_url .= '&error='.urlencode("$error_mesg").$query_string;
    Redirect($bad_url);
    }
    --[ END ]--

    I hope you can add this to the release as it makes a nice feature.

    Also wanted to say that this is an excellent script. I was using Jack's Formmail script before this and found a few problems with it. This one seems top notch. Nice work guys.


    Best regards,
    CornerNote
    www.mrphp.com.au

  2. #2
    Join Date
    Dec 2003
    Posts
    3,901

    Default Re: Return All Variables To Form Page On Error

    Thanks for the sample code.

    We're planning to add this feature soon.

    If I'm not mistaken, your solution requires that the $bad_url is a script (e.g. a PHP script) that can insert the field values into the HTML that's sent to the browser.

    Is that correct?
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  3. #3
    Join Date
    Apr 2004
    Posts
    5

    Default Re: Return All Variables To Form Page On Error

    Hello,

    Yes - that is correct. Using this method the user can come back to the same page (without using the back button), with the error message reporting the fields that are incorrect from the error variable (or any other error message that is reported) and not have to refill the fields again. This is particurly useful for large forms.

    Best regards,
    CornerNote
    www.mrphp.com.au

  4. #4
    Join Date
    Apr 2004
    Posts
    5

    Default Re: Return All Variables To Form Page On Error

    Hello,

    I notice you have included something similar to this in the new formmail. It returns the fields to the form except it removes $realname and $email and all other variables in the $SPECIAL_VALUES array.

    To overcome this you can edit formmail.php
    --[ CHANGE ]--
    Redirect($bad_url);
    --[ TO ]--
    Redirect($bad_url.'&SPECIAL_VALUES='.serialize($SPECIAL_VALUES));
    --[ END ]--

    At the top of your form.php add this:
    <?php $SPECIAL_VALUES=unserialize(stripslashes($SPECIAL_VALUES)); ?>

    Then you can print the variables in your form elements like this:
    <input type="text" name="realname" value="<?=$SPECIAL_VALUES["realname"]; ?>">
    <input type="text" name="email" value="<?=$SPECIAL_VALUES["email"]; ?>">


    Best regards,
    Brett

    mrphp.com.au :: We Create Code
    Last edited by cornernote; 20-May-2004 at 06:13 AM.

  5. #5
    Join Date
    Dec 2003
    Posts
    3,901

    Default Re: Return All Variables To Form Page On Error

    Hi Brett,

    Thanks for the code changes.

    The reason we don't send "special values" to the bad_url is that most of these are hidden variables, and you generally want these to remain static.

    To achieve the same result as your code changes (re-entry of realname and email), you can do this with FormMail v2.00 and above:
    1. Create fields for the user name and email address called something other than "realname" and "email", respectively. For example, call them "UserName" and "EmailAddr".
    2. Use the "derive_fields" feature to map these to the required special names:
      Code:
      <input type="hidden" name="derive_fields" value="realname=UserName,email=EmailAddr">
    If using our fmbadhandler.php with a form in a .htm document, the above technique will ensure that the user's name and email address are filled in when they return to the form.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  6. #6
    Join Date
    Apr 2004
    Posts
    5

    Default Re: Return All Variables To Form Page On Error

    Hello,

    The only problem with this is that the fields all come through on the email. Is it possable to remove the fields that new fields are derived from?


    Best regards,
    Brett

  7. #7
    Join Date
    Dec 2003
    Posts
    3,901

    Default Re: Return All Variables To Form Page On Error

    Hi Brett,

    Having those fields included is a feature if you want it, and an annoyance if you don't.

    You can exclude any value (except specials) by using this hidden field:
    Code:
    <input type="hidden" name="mail_options" value="Exclude=field1;field2;field3">
    There are other mail_options you can use (they're documented in formmail.php, but we'll also provide a HOW-TO guide for the mail_options feature soon.)
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  8. #8
    Join Date
    Apr 2004
    Posts
    5

    Default Re: Return All Variables To Form Page On Error

    Hello,

    Very cool indeed. This is the best formmail ever.




    Best regards,
    Brett

  9. #9
    Join Date
    Oct 2004
    Posts
    5

    Default Re: Return All Variables To Form Page On Error

    I'm a newbie, and I'm just not understanding how to return the form variables back to the original form if there was an error. I have a long form, and do not want to have them have to enter the info again.

    I'm not sure what to do with bad_url or what else I need to accomplish this.

    THANKS!
    Diane

  10. #10
    Join Date
    Dec 2003
    Posts
    3,901

    Default Re: Return All Variables To Form Page On Error

    Hi,

    Have you read the HOW-TO guide on error handling?

    It's here: http://www.tectite.com/fmhowto/adverror.php

    If you have read that and still can't figure out what to do, you may need to hire the services of a programmer or web designer.

    Basically, you can use our FMBadHandler script (fmbadhandler.php). Configure it and upload it to your server. Set bad_url to point to that FMBadHandler script, create a template to show the errors to the user, put that in bad_template, and set this_form to be the URL of the form.

    The reload of the form is then handled automatically by FMBadHandler.

    Unfortunately, this process does require a little more than a basic understanding of HTML and server administration.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Removing empty variables from eMail reply
    By Prospero in forum FormMail Subscription Support
    Replies: 4
    Last Post: 25-Jul-2004, 08:22 AM
  2. No return link for badhandler
    By ptr in forum FormMail Subscription Support
    Replies: 3
    Last Post: 27-May-2004, 12:27 AM
  3. scrip of error page
    By frans47 in forum FormMail Subscription Support
    Replies: 4
    Last Post: 19-May-2004, 04:08 AM
  4. Submitted form output onto HTML page?
    By LKimber in forum FormMail Subscription Support
    Replies: 2
    Last Post: 13-Apr-2004, 11:39 AM
  5. Adding Attachment Variables
    By Bella in forum FormMail Subscription Support
    Replies: 1
    Last Post: 12-Apr-2004, 10:43 AM

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