PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Clear fields after submit

  1. cwoodside
    Member

    Is there a way to clear the form fields after submitting so when the user uses the back function they can't resubmit the same information over again?

    I have found code to clear by ip address or time period, but my users may submit many forms in an hour and they have several locations with many users that use the same ip address, so that would lock out other users.

    Is the a way to delete the cookie upon submission or ?!?

    Posted 12 years ago on Tuesday August 28, 2012 | Permalink
  2. This can be done with jQuery or JavaScript. Please see here for one possible solution:
    http://stackoverflow.com/questions/8861181/clear-all-fields-in-a-form-upon-going-back-with-browser-back-button?rq=1

    Posted 12 years ago on Wednesday August 29, 2012 | Permalink
  3. cwoodside
    Member

    I tried with this code in the header.php file and it didn't work - should it go elsewhere, is the code correct?

    $(window).bind("pageshow", function() {
      // update hidden input field
    });

    I also tried this in the same place without any luck:

    $(':input','gform_1')
     .not(':button, :submit, :reset, :hidden')
     .val('')
     .prop('checked', false)
     .prop('selected', false);
    Posted 12 years ago on Thursday August 30, 2012 | Permalink
  4. Can you post a link to your site where you implemented this so we can take a look at how it's working please?

    Posted 12 years ago on Friday August 31, 2012 | Permalink
  5. cwoodside
    Member

    Sure - it's http://www.earnvpoints.com/vpadmin/awardentryform/

    For access:

    u-gravitytest
    pw-1234567

    Posted 12 years ago on Friday August 31, 2012 | Permalink
  6. I see this error on your page:

    Timestamp: 9/11/2012 10:08:01 PM
    Error: TypeError: $ is not a function
    Source File: http://www.earnvpoints.com/vpadmin/login/?action=login
    Line: 62

    The reason for this is that you cannot use $ by itself. $ is reserved for Prototype in WordPress. To use jQuery code, you might need to do something like this:

    [js]
    <script type='text/javascript'>
    jQuery(window).bind("pageshow", function() {
      // update hidden input field
    });
    </script>

    Additionally, I see this text in the source of the page, which would work fine for PHP comments but not HTML comments:

    [php]
    /**
     * MY CUSTOM INCLUDES
     */

    Remove that or properly comment it out.

    Resolve those issues and we will move on to the next problem.

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  7. cwoodside
    Member

    OK, I fixed those with no changes to the page or how it works...

    Not sure why the "my custom includes" was there, this code is in a php file - header.php so I just deleted them, but will have a hard time finding my code in the future.

    As for the $ script, that was also in header.php and I had read that you couldn't use it, but this was the code on the page you sent me to - I just copied it over - (http://www.gravityhelp.com/forums/topic/clear-fields-after-submit#post-73166)
    I did change it what you suggested but it still does not clear fields, seems to have no effect at all

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  8. [js]
    $(window).bind("pageshow", function() {
      // update hidden input field
    });

    The line commented out with the // is just a comment. This function will not do anything. The comment was a placeholder for your code to clear the fields. It was referred to as pseudo code on stackexchange.

    I tried to look at this but could not get past the validation for the "employee #" - can you give me an example of good data to submit here, so I can get to the next page and see if using the browser back button breaks anything.

    Posted 12 years ago on Friday September 14, 2012 | Permalink
  9. cwoodside
    Member

    Sure,

    f & l name can be anything - e# needs to be 4letters4numbers (aaaa1111) and award has to be 100-99999. you then automatically get an add a line button, you can go up to 40. I find that 2-3 is great for testing.

    Posted 12 years ago on Monday September 17, 2012 | Permalink
  10. Rather than trying to script it to clear the form when using the browser back button, how about adding a big button on the confirmation page which says "Enter more awards" or something, then load the initial form page, which will be clear of any previously entered form data.

    The other problem I ran into was that when using the list type field, you might have entered four lines of data, but going back, maybe you need 2 lines or 20 lines. Going back to a screen with four lines of input to be entered makes no sense.

    Trying solutions which break the browser back button or try to work around default browser functionality is going to troublesome.

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink
  11. Also, I did submit a couple entries and then used the browser back button. I see this script in the source:

    [js]
    <script type='text/javascript'>
    jQuery(window).bind("pageshow", function() {
      // update hidden input field
    });
    </script>

    The commented line "update hidden input field" is just that: a comment. It will not do anything. That is where you would add your code to clear the form fields. That was just an example of how to do it. We can't do the coding for you but can try to help figure out what needs to be done.

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink
  12. cwoodside
    Member

    I'm not worried about them going back to enter more lines, but it seems very easy to submit without meaning to, I did several times when entering data.
    These people are not at all computer savvy and it is just natural instinct to hit the back button if you didn't mean to submit and keep entering not realizing that what you already typed will now be entered twice.
    I was trying to avoid this, I can see it happening a lot and the data will be auto dumped into a database, so they will all have to be manually updated - a potential nightmare.
    I'm sorry I know nothing about jquery and have no idea what to put in that place.
    I've looked up several examples and I have to say they are all way beyond my comprehension.
    I know it resets if I just redirect to the same page again (reload the page), but I needed to give them a form to print out their data so they have copy of what they sent.
    I guess another option is to have their email and send a copy of the submission and then redirect to the form again - would that work? Not preferred, but I've had to work around a lot already!

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink
  13. cwoodside
    Member

    I'm not worried about them going back to enter more lines, but it seems very easy to submit without meaning to, I did several times when entering data.
    These people are not at all computer savvy and it is just natural instinct to hit the back button if you didn't mean to submit and keep entering not realizing that what you already typed will now be entered twice.
    I was trying to avoid this, I can see it happening a lot and the data will be auto dumped into a database, so they will all have to be manually updated - a potential nightmare.
    I'm sorry I know nothing about jquery and have no idea what to put in that place.
    I've looked up several examples and I have to say they are all way beyond my comprehension.
    I know it resets if I just redirect to the same page again (reload the page), but I needed to give them a form to print out their data so they have copy of what they sent.
    I guess another option is to have their email and send a copy of the submission and then redirect to the form again - would that work? Not preferred, but I've had to work around a lot already!

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink
  14. You could do exactly as you stated in the last paragraph: send a copy of their submission to their email and have a link hard coded there for them to go back to the form to enter more.

    You could also add a pre-submission confirmation page which they would see before final submission: http://gravitywiz.com/2012/08/04/better-pre-submission-confirmation/

    Also, to make things simpler, you could allow just one entry per screen, and then redirect to the form when they submit (use a confirmation redirect.)

    I'm sure there are a lot of ways to make it easier for your users to submit their data.

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink
  15. cwoodside
    Member

    OK, so I'm using the pre-submit - That is going to work great, just one problem...

    On the second page where it shows the data, there is a significant amount of space between the top percentage bar and my inserted table. I have been over the code and tried several things with no changes - any ideas?

    Posted 12 years ago on Friday September 21, 2012 | Permalink