Hi, I've been trying to get this working correctly for a while now and the question I have is really two fold.
Firstly here's what I'm trying to achieve:
Users register using your registration plugin, and part of the form asks for the postcode.
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.
The logic is as follows:
Get postcode,
Make sure it's all upper case and remove spaces,
Add -001 to the end of the postcode,
Check to see if this username is already in use,
If it is increase to 002 and try again,
If it's not then continue,
Post unique username back to the form to allow the user to register,
So the final format should look like this - AB12CD-002
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).
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;
Any and all help with either the specific issue or the whole problem would be greatly received!
Here's what I've got so far (the population code comes from other posts on here):
add_filter("gform_pre_render_1", "populate_previous_page_data");
function populate_previous_page_data($form){
$page_number = rgpost("gform_target_page_number_{$form["id"]}"); //Set $page_number to the form id ??
$page_number = !is_numeric($page_number) ? 1 : $page_number; //Make the form id a usable number ??
foreach($form['fields'] as &$field) { //Loop through each form field in the variable $field
if($field['id'] != 9) // If field is not equal to 9 (or target for dynamically populating)
$field_page = rgar($field, 'pageNumber'); //$field_page equals the form page the currently looked at field is on
if($page_number > $field_page) //If $page_number is greater than $field_page then
continue; //Exit loop and restart
$user_id = rgpost('input_2_5');
$user_id = preg_replace('/\s+/', '', $user_id);
$user_id = strtoupper($user_id);
$count = 1;
$user_id_no = 001;
//$user_id_no = printf("%'03", $user_id_no);
$user_id = $user_id.$user_id_no;
$field['defaultValue'] = $user_id;
}
return $form;
}