<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Dynamically Populating from Previous Form Page with Editing Issue</title>
		<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-from-previous-form-page-with-editing-issue</link>
		<description>Gravity Support Forums Topic: Dynamically Populating from Previous Form Page with Editing Issue</description>
		<language>en-US</language>
		<pubDate>Thu, 09 Apr 2026 07:51:20 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/dynamically-populating-from-previous-form-page-with-editing-issue" rel="self" type="application/rss+xml" />

		<item>
			<title>theslink2000 on "Dynamically Populating from Previous Form Page with Editing Issue"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-from-previous-form-page-with-editing-issue#post-60742</link>
			<pubDate>Wed, 30 May 2012 08:55:52 +0000</pubDate>
			<dc:creator>theslink2000</dc:creator>
			<guid isPermaLink="false">60742@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Well, I've had no reply from anyone but I have managed to find a workable solution so I'll post it here in case anyone stumbles across this post and wants the answer.&#60;/p&#62;
&#60;p&#62;Ultimately this post has provided the majority of the solution:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://www.gravityhelp.com/forums/topic/dynamically-populate-age&#34; rel=&#34;nofollow&#34;&#62;http://www.gravityhelp.com/forums/topic/dynamically-populate-age&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The reason I had loads of boxes with bits of data is that the -001 section was set and the postcode wasn't populated until after the first page submission.  Using $field[default_Value'] as a return was a mistake.  Here is how I've modified the code to work:&#60;/p&#62;
&#60;p&#62;add_filter('gform_validation_1', 'find_age');&#60;br /&#62;
function find_age($validation_result) {&#60;/p&#62;
&#60;p&#62;    // 2 - Get the form object from the validation result&#60;br /&#62;
    $form = $validation_result[&#34;form&#34;];&#60;/p&#62;
&#60;p&#62;    // 3 - Get the current page being validated&#60;br /&#62;
    $current_page = rgpost('gform_source_page_number_' . $form['id']) ? rgpost('gform_source_page_number_' . $form['id']) : 1;&#60;/p&#62;
&#60;p&#62;    // 4 - Loop through the form fields&#60;br /&#62;
    foreach($form['fields'] as &#38;amp;$field){&#60;/p&#62;
&#60;p&#62;        // 5 - If the field does not have our designated CSS class, skip it&#60;br /&#62;
        if(strpos($field['cssClass'], 'postcode') === false)&#60;br /&#62;
            continue;&#60;/p&#62;
&#60;p&#62;        // 6 - Get the field's page number&#60;br /&#62;
        $field_page = $field['pageNumber'];&#60;/p&#62;
&#60;p&#62;        // 7 - Check if the field is hidden by GF conditional logic&#60;br /&#62;
        $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());&#60;/p&#62;
&#60;p&#62;        // 8 - If the field is not on the current page OR if the field is hidden, skip it&#60;br /&#62;
        if($field_page != $current_page &#124;&#124; $is_hidden)&#60;br /&#62;
            continue;&#60;/p&#62;
&#60;p&#62;        // 9 - Get the submitted value from the $_POST&#60;br /&#62;
		$field_value = rgpost(&#34;input_2_5&#34;);&#60;br /&#62;
		$field_value = preg_replace('/\s+/', '', $field_value);   //Remove spaces and any character that isn't a number or letter&#60;br /&#62;
		$field_value = strtoupper($field_value);   //Convert to uppercase&#60;/p&#62;
&#60;p&#62;		$user_id = build_id($field_value, 1);&#60;/p&#62;
&#60;p&#62;		foreach($form['fields'] as &#38;amp;$field2){&#60;br /&#62;
			if(strpos($field2['cssClass'], 'userid') === false) //loop through fields again to find the &#34;Age&#34; field&#60;br /&#62;
            continue;&#60;/p&#62;
&#60;p&#62;			$field2[&#34;defaultValue&#34;] = $user_id; //add calculated age as default value to &#34;Age&#34; field&#60;br /&#62;
}}&#60;br /&#62;
$validation_result['form'] = $form; //manipulate $validation_result with modified $form&#60;/p&#62;
&#60;p&#62;    // 15 - Return the validation result&#60;br /&#62;
    return $validation_result;&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;function build_id ($pcode_id, $assigned_id_no) {	//Builds complete user id&#60;/p&#62;
&#60;p&#62;	 do {&#60;br /&#62;
            $cmplt_id = $pcode_id . &#34;-&#34; . number_pad($assigned_id_no, 3);  //Puts postcode string and calls the number padding function to add the leading 0's&#60;br /&#62;
                        $assigned_id_no++;&#60;br /&#62;
        }&#60;br /&#62;
        while(username_exists($cmplt_id));&#60;br /&#62;
        return $cmplt_id;&#60;/p&#62;
&#60;p&#62;	return $cmplt_id;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;function number_pad($number,$n) {  //Takes a string and add's however many 0's (or other character placed there) to the left of the string&#60;br /&#62;
return str_pad((int) $number,$n,&#34;0&#34;,STR_PAD_LEFT);&#60;br /&#62;
}
&#60;/p&#62;</description>
		</item>
		<item>
			<title>theslink2000 on "Dynamically Populating from Previous Form Page with Editing Issue"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-from-previous-form-page-with-editing-issue#post-60000</link>
			<pubDate>Wed, 23 May 2012 05:45:02 +0000</pubDate>
			<dc:creator>theslink2000</dc:creator>
			<guid isPermaLink="false">60000@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Has no one got any ideas?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>theslink2000 on "Dynamically Populating from Previous Form Page with Editing Issue"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-from-previous-form-page-with-editing-issue#post-59163</link>
			<pubDate>Wed, 16 May 2012 12:39:03 +0000</pubDate>
			<dc:creator>theslink2000</dc:creator>
			<guid isPermaLink="false">59163@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi, I've been trying to get this working correctly for a while now and the question I have is really two fold.&#60;/p&#62;
&#60;p&#62;Firstly here's what I'm trying to achieve:&#60;/p&#62;
&#60;p&#62;Users register using your registration plugin, and part of the form asks for the postcode.&#60;br /&#62;
The second page pulls the postcode from the first page, but before it is populated back into the form it undergoes editing to produce a username that users will have to use to register on the site.&#60;/p&#62;
&#60;p&#62;The logic is as follows:&#60;/p&#62;
&#60;p&#62;Get postcode,&#60;br /&#62;
Make sure it's all upper case and remove spaces,&#60;br /&#62;
Add -001 to the end of the postcode,&#60;br /&#62;
Check to see if this username is already in use,&#60;br /&#62;
If it is increase to 002 and try again,&#60;br /&#62;
If it's not then continue,&#60;br /&#62;
Post unique username back to the form to allow the user to register,&#60;/p&#62;
&#60;p&#62;So the final format should look like this - AB12CD-002&#60;/p&#62;
&#60;p&#62;I'm having problems getting the formatting and check working so if anyone can help me with the over all problem that'd be great (I'll include what I've got so far at the end).&#60;/p&#62;
&#60;p&#62;The main problem that has caused me to post here is that when I try and concatenate the two halves of the username (join the postcode and number) the post back to GForms seems output the second variable to every field that allows numbers!  I have no idea why but I think it has something to do with the last line: $field['defaultValue'] = $user_id;&#60;/p&#62;
&#60;p&#62;Any and all help with either the specific issue or the whole problem would be greatly received!&#60;/p&#62;
&#60;p&#62;Here's what I've got so far (the population code comes from other posts on here):&#60;/p&#62;
&#60;p&#62;add_filter(&#34;gform_pre_render_1&#34;, &#34;populate_previous_page_data&#34;);&#60;br /&#62;
function populate_previous_page_data($form){&#60;/p&#62;
&#60;p&#62;    $page_number = rgpost(&#34;gform_target_page_number_{$form[&#34;id&#34;]}&#34;);  //Set $page_number to the form id ??&#60;br /&#62;
    $page_number = !is_numeric($page_number) ? 1 : $page_number;	//Make the form id a usable number ??&#60;/p&#62;
&#60;p&#62;    foreach($form['fields'] as &#38;amp;$field) {	//Loop through each form field in the variable $field&#60;/p&#62;
&#60;p&#62;        if($field['id'] != 9) // If field is not equal to 9 (or target for dynamically populating)&#60;/p&#62;
&#60;p&#62;        $field_page = rgar($field, 'pageNumber');	//$field_page equals the form page the currently looked at field is on&#60;/p&#62;
&#60;p&#62;        if($page_number &#38;gt; $field_page)	//If $page_number is greater than $field_page then&#60;br /&#62;
            continue;	//Exit loop and restart&#60;/p&#62;
&#60;p&#62; 		$user_id = rgpost('input_2_5');&#60;br /&#62;
		$user_id = preg_replace('/\s+/', '', $user_id);&#60;br /&#62;
		$user_id = strtoupper($user_id);&#60;/p&#62;
&#60;p&#62;		$count = 1;&#60;br /&#62;
		$user_id_no = 001;&#60;br /&#62;
		//$user_id_no = printf(&#34;%'03&#34;, $user_id_no);&#60;br /&#62;
		$user_id = $user_id.$user_id_no;&#60;br /&#62;
		$field['defaultValue'] = $user_id;&#60;/p&#62;
&#60;p&#62;    }&#60;/p&#62;
&#60;p&#62;    return $form;&#60;br /&#62;
}
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
