- This topic has 2 replies, 2 voices, and was last updated 4 years, 2 months ago by
pastor@trinityslayton.net.
-
AuthorPosts
-
8th February 2021 at 3:44 pm #5383
pastor@trinityslayton.net
ParticipantGreetings,
Another quick question about formatting.
Addresses are stored in a single field which includes the street address, the city, the state, and the zip code. These are separated by commas, so running a post-download filter to put the four pieces of information into individual fields isn’t very difficult. However, this would be easier if we could pass a parameter to the label / csv download module to split those fields into their components, saving the need for another step after the labels are downloaded.
I’m also curious why the address is conflated rather than being in separate fields? It is easy to concatenate fields, it is a bit more problematic to split them.
I realize that this plugin is written and maintained in Great Britain, so the address lines will not be the same as in the United States. Is there an equivalent of City, State, Zip which would make the US mailing labels easier to format?
Thanks.
8th February 2021 at 3:56 pm #5385Andy Moyle
KeymasterHi there,
Address formatting for an international plugin is a total nightmare! I use one field because there are lots of ways of ordering the elements of an address in the different nations. See https://en.wikipedia.org/wiki/Address.To have individual elements would mean detecting the nation and knowing the order for forms – not everyone bothers setting the locale on their WP install either! I’m in the UK and we have two ways of formatting addresses depending on whether the house has a number or a name!
The Google map api wants the address as one line so it made sense to make it easy for the user to enter the address simply and store it that way
The CSV and mailing labels in the plugin just put a line break after each comma.
A simple str_replace(“,”,”, \r\n”,$address) would work or explode(“,”,$address) to put it in an array for further processing8th February 2021 at 4:16 pm #5386pastor@trinityslayton.net
ParticipantI modified pdf_creator.php to handle the addresses for both individuals and households. My mods are the same for both. Here is the code for individuals.
=============================
foreach ($results as $row)
{$name=implode(” “,array_filter(array($row->first_name.$row->prefix,$row->last_name)));
$address=$row->address;
$row->address=str_replace(“, “,”,”,$row->address);
$add=explode(“,”,$row->address);
// modified 2/8/2021 to give US style mailing labels
$street = $add[0];
$city = $add[1];
$state = $add[2];
$zip = $add[3];
// $add=$name.”\n”.implode(“,\n”,$add);
$add1=$name.”\n”.$street.”\n”.$city.”, “.$state.” “.$zip;
// $pdflabel->Add_Label($add);
$pdflabel->Add_Label($add1);}
$pdflabel->Output();
//end of mailing labels
}
exit(); -
AuthorPosts
- You must be logged in to reply to this topic.