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.

populate field with value field of previous page

  1. jramerman

    In my form (to register the kilometres a car has driven on weekdays) I want to reuse the value that's entered in a number field on page 2 (monday) to be populated to a number field in page 3 (tuesday) (page 1 contains general information about the driver).

    The value the car has ended with on monday must be the populated starting kiliometres for tuesday and so on for the rest of the week.

    I have been reading several topics on this forum and thought I was nearby a solution with this

    but I can't seem to understand the last part of the code mentioned:

    // update this to the ID of the field whose value you wish to call
    // '16.3' = example, first name of a Name field
    // '16.6' = example, last name of a Name field
    $field['defaultValue'] = rgpost('input_16_3');

    in my form (i can't send a URL because of security) I have form id = 5, field that should be populated id=87 and field that contains the value i want to reuse=9

    I also wonder if I need to change anything on the pagenumbering in my case (monday is page 2, tuesday is page 3).

    Then last but not least. If I use this code, my pre-populated field with the user_name displayed is changed to empty...

    Since the field is a number field I already have been thinking of a workaround since the field value I want to be populated is in a number field I could use the new calculation function on page 3 (just saying: use field 9 + zero). That works basically like expected, but the problem I face there is the thousand seperator that is bothering me. People filling out this form won't type their kilometres with a thousand seperator...

    Hope somebody can help me out on either one of these two 'solutions'.


    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  2. jramerman

    can anybody help me on this one?

    Posted 11 years ago on Monday July 9, 2012 | Permalink
  3. Can you use to show me your PHP function code you are using/have placed?

    Posted 11 years ago on Monday July 9, 2012 | Permalink
  4. theslink2000

    I'm also having problems with the code detailed on the post jramerman mentioned. I can make it work by changing the last bit to:

    '$field['defaultValue'] = rgpost('input_7');'

    Even though the html field id is input_1_7. The other problem is that it populates every field of that kind on the page so I have a series of post fields on page 4 and it puts the content in every one of them! If I change anything such as changing defaultValue to Content or to correct input ID it won't populate.

    I'm really struggling with dynamic population in general it just seems over complicated, the documentation is little more than basic pointers with most of the forum posts just pointing at them, which is unhelpful.

    In light of this I'd like to suggest a new built in feature where a field is available on the advanced settings which allows the user to enter a field ID from that form and it will dynamically populate automatically.

    Posted 11 years ago on Tuesday July 10, 2012 | Permalink
  5. jramerman

    If I use this code in functions.php the problem is like described under 1.

    I now just found out, that for the workaround mentioned above under 2. the problem is that the thousand seperator is used as a decimal seperator.

    for example monday starting on 10400 and ending on 10500 gives starting on tuesday 10.500 When used further on in the calculation this is been seen as 10,5 instead of 10 thousand 500. So probably this is the real problem in my case...? In the field, the format is set to 9.999,99

    I now changed the calculation by adding *1000 to it and it now seems to work....!!

    But I am still curious why this code isn't working like expected.

    Posted 11 years ago on Tuesday July 10, 2012 | Permalink
  6. theslink2000

    Could you pastie you're working code please bud? Mine looks exactly like the one you've posted here, maybe if I see what actually works for you we can finally figure out what's going on here!

    Posted 11 years ago on Tuesday July 10, 2012 | Permalink
  7. theslink2000

    Also these may be of some interest. I can get neither to work so if any admins are reading this and want to help please jump in!

    Field ID's being used - Take contents from field ID 18 and put it into field ID 24 on a 4 page form, form ID = 1 (note in the source code field 18 seems to have an ID of tos-18)


    My Code:

    This one also came from the GForms forums and uses JQuery.

    Both of these seem to make perfect sense and work as I would have expected this to work but for some reason don't! This is getting really annoying so fingers crossed we can get somewhere.

    Also forgive me if I've missed the point slightly but could you not convert the numerical field to a string, use string manipulation to format it correctly and then pass it to the process afterwards, so GForms will treat it as a string so you can use input masks and validation to format it correctly and then convert it to a number for work behind the scenes?

    Posted 11 years ago on Tuesday July 10, 2012 | Permalink
  8. elizabethanne

    just tried that last pastie - isn't working for me either. i need the value from a previous field on the page. hopefully someone can step in and help!

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  9. theslink2000

    After experimenting some more that last pastie I posted will work on the same page wonderfully cause I've used it to fill some hidden post fields from some of the more advanced fields such as the address field.

    However, I've manage to get one bit of code to pass a value between page one and two here:

    This has been outlined somewhere else on the GForms forums but I can't find it so I'm reposting mine but IT IS NOT MY WORK. Ok so that's clear, I've posted a bit to much here, it's the complete set of functions to build a user ID out of a post code entry and then modifying the string and returning it to a field on the next page. I included it all to allow anyone unsure to pick through it and understand and make sure there's nothing left to doubt about odd function calls. With this I've managed to get it to post the same thing in multiple fields by giving the output a second if statement and CSS name but I haven't been able to apply it to another setup for some reason.

    I'm sorry if that's a bit wordy but I just want to avoid doing what I've seen on here and assuming people get things when they may not, I rarely do lol. Once again it's not my work but I've commented it as I've figured it out, hope this helps elizabethanne.

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  10. elizabethanne

    @theslink2000 so you got this pastie to work? i put it into my functions.php file, updated the form ID and input field IDs, and nada. :(

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  11. theslink2000

    I got it to work but as I said only between fields on the same page. The way it works to the best of my understanding is when you click into the field you want to populate from it loads the script and then when you click elsewhere it fires the populate function.

    But this will only work between two forms on the same page NOT between pages. If it's not working for you the only thing I can think of is that perhaps you haven't got JQuery active in your theme, that was a problem I had to start with.

    But as I said in my previous post is the only script I've manage to get to pass field data between pages I'm afraid.

    PS - Sorry about the delay I'm in GMT time zone so it was late :-)

    Posted 11 years ago on Friday July 13, 2012 | Permalink