scavanaugh Posted April 29, 2015 Share Posted April 29, 2015 I'm trying to get a mailing address to appear in a stacked format in my form mail email return. The address is selected by the user from a drop down list then the form is submitted. It runs through a PHP form handler and is output as an HTML email. I understand that something like this would possibly work, though it appears that there are a few variations. $address = str_replace(",", ",\n", $_POST["shippingaddress"]); The thing I'm really not sure about is where in the PHP form handler to insert this line of code? Here's a link to the code for the form handler. http://scavanaugh.com/TESTfm.txt Any help with this is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/ Share on other sites More sharing options...
ginerjm Posted April 29, 2015 Share Posted April 29, 2015 You're outputting an html formatted email, so just use std. html to format your email. Use a <br> tag between the lines of the address - no? Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510301 Share on other sites More sharing options...
scavanaugh Posted April 29, 2015 Author Share Posted April 29, 2015 You're outputting an html formatted email, so just use std. html to format your email. Use a <br> tag between the lines of the address - no? I tried this and it didn't work </li><label for="shippingaddress">Shipping Address</label><li> <li><select id="shipaddress" name="shippingaddress" dir="ltr" lang="en"> <option>80 Allstate Parkway,<br /> Markham ON,<br /> L3R 6H3</option> <option>30 High Meadow, Toronto ON, M6L 2Z5</option> <option>4000 Victoria Park Avenue, Toronto ON, M2H 3P4 </option> ... </select></li> Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510310 Share on other sites More sharing options...
Ch0cu3r Posted April 29, 2015 Share Posted April 29, 2015 This is because dropdown menus cannot contain newlines. Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510311 Share on other sites More sharing options...
scavanaugh Posted April 29, 2015 Author Share Posted April 29, 2015 This is because dropdown menus cannot contain newlines. is there a way to replace the commas with line breaks? Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510313 Share on other sites More sharing options...
Psycho Posted April 29, 2015 Share Posted April 29, 2015 is there a way to replace the commas with line breaks? Didn't he just say line breaks are not supported in SELECT lists? The existence or not of a comma has nothing to do with it. If you weren't including this content in an email, you could use JQuery to build a "custom" select list object to display it however you want. But, I am pretty certain you can't run JavaScript in an HTML email. If you absolutely need to display with line breaks, you would have to provide a link into the email to open the form in a web page. Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510323 Share on other sites More sharing options...
ginerjm Posted April 29, 2015 Share Posted April 29, 2015 Have you ever seen a list box with line feeds in it? Can't be done! And - just why are you using a dropdown in an email? Is this going to be some kind of input to another script? Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510327 Share on other sites More sharing options...
scavanaugh Posted April 29, 2015 Author Share Posted April 29, 2015 Have you ever seen a list box with line feeds in it? Can't be done! And - just why are you using a dropdown in an email? Is this going to be some kind of input to another script? All I'm looking for is the Mailing address to appear in the email to the recipient like this 123 Maple St. Nowhere USA Right now it gets emailed like this: 123 Maple St, Nowhere, USA ? Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510333 Share on other sites More sharing options...
Psycho Posted April 29, 2015 Share Posted April 29, 2015 So, you don't want the address to be displayed in a select list - that is important information. Do you have code that creates the email or are you using some 3rd party script for the email? You could start by using a separate value from the label for the options: [coed]<li><select id="shipaddress" name="shippingaddress" dir="ltr" lang="en"> <option value="80 Allstate Parkway<br />Markham ON<br />L3R 6H3">80 Allstate Parkway, Markham ON, L3R 6H3</option> <option value="30 High Meadow, Toronto ON<br />M6L 2Z5">30 High Meadow, Toronto ON, M6L 2Z5</option> <option value="4000 Victoria Park Avenue<br />Toronto ON<br />M2H 3P4">4000 Victoria Park Avenue, Toronto ON, M2H 3P4</option>[/code] If you are using a 3rd party script to generate the emails, it will likely take more effort to find and modify the right code to work properly. But, if you wrote the code to generate the email, then show the lines that generate the content from the POSTed values. Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510336 Share on other sites More sharing options...
scavanaugh Posted April 30, 2015 Author Share Posted April 30, 2015 Have you ever seen a list box with line feeds in it? Can't be done! And - just why are you using a dropdown in an email? Is this going to be some kind of input to another script? It's going through a PHP form handler Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510363 Share on other sites More sharing options...
scavanaugh Posted April 30, 2015 Author Share Posted April 30, 2015 So, you don't want the address to be displayed in a select list - that is important information. Do you have code that creates the email or are you using some 3rd party script for the email? You could start by using a separate value from the label for the options: [coed]<li><select id="shipaddress" name="shippingaddress" dir="ltr" lang="en"> <option value="80 Allstate Parkway<br />Markham ON<br />L3R 6H3">80 Allstate Parkway, Markham ON, L3R 6H3</option> <option value="30 High Meadow, Toronto ON<br />M6L 2Z5">30 High Meadow, Toronto ON, M6L 2Z5</option> <option value="4000 Victoria Park Avenue<br />Toronto ON<br />M2H 3P4">4000 Victoria Park Avenue, Toronto ON, M2H 3P4</option>[/code] If you are using a 3rd party script to generate the emails, it will likely take more effort to find and modify the right code to work properly. But, if you wrote the code to generate the email, then show the lines that generate the content from the POSTed values. Yeah I tried that already and it didn't change anything. Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510364 Share on other sites More sharing options...
scavanaugh Posted April 30, 2015 Author Share Posted April 30, 2015 This is how I found to do it but I dont't know where to insert the line in the PHP form handler. $address = str_replace(",", ",\n", $_POST["shippingaddress"]); (I've seen this modified also) Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510365 Share on other sites More sharing options...
ginerjm Posted April 30, 2015 Share Posted April 30, 2015 Hard to help someone who won't share their code. One line is not much of a context to follow. Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510409 Share on other sites More sharing options...
Psycho Posted April 30, 2015 Share Posted April 30, 2015 It's the form handler code that needs to be modified. Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510425 Share on other sites More sharing options...
scavanaugh Posted April 30, 2015 Author Share Posted April 30, 2015 So, you don't want the address to be displayed in a select list - that is important information. Do you have code that creates the email or are you using some 3rd party script for the email? You could start by using a separate value from the label for the options: [coed]<li><select id="shipaddress" name="shippingaddress" dir="ltr" lang="en"> <option value="80 Allstate Parkway<br />Markham ON<br />L3R 6H3">80 Allstate Parkway, Markham ON, L3R 6H3</option> <option value="30 High Meadow, Toronto ON<br />M6L 2Z5">30 High Meadow, Toronto ON, M6L 2Z5</option> <option value="4000 Victoria Park Avenue<br />Toronto ON<br />M2H 3P4">4000 Victoria Park Avenue, Toronto ON, M2H 3P4</option>[/code] If you are using a 3rd party script to generate the emails, it will likely take more effort to find and modify the right code to work properly. But, if you wrote the code to generate the email, then show the lines that generate the content from the POSTed values. Hi I tried inserting <br /> as suggested but didn't work. I posted a link to the form handler code (3rd party code) in my first post, here it is again http://scavanaugh.com/TESTfm.txt Take a look if you like and let me know what you think. Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510455 Share on other sites More sharing options...
ginerjm Posted April 30, 2015 Share Posted April 30, 2015 I prefer to see code posted on the forum, not somewhere else. Quote Link to comment https://forums.phpfreaks.com/topic/295950-inserting-line-breaks/#findComment-1510457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.