Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Replace ',' with '<br>' or similar for html template

  1. #1
    Join Date
    May 2011
    Posts
    7

    Default Replace ',' with '<br>' or similar for html template

    I have an order form where 3 input fields which are generated by javascript as an array. When I submit the order as text or html email, I get comma separated values for each field.

    Here are the HTML input input's:

    <input type="hidden" name="item_qty[${code}]" value="${qty}" />
    <input type="hidden" name="item_description[${code}]" value="${name}" />
    <input type="hidden" name="item_price[${code}]" value="${price}" />

    Which would be generated (per item) as:
    <input type="hidden" name="item_qty[unique_product_code]" value="qty_value">
    <input type="hidden" name="item_description[unique_product_code]" value="description_value">
    <input type="hidden" name="item_price[unique_product_code]" value="price_value">

    When I use the following input fields in html template:
    $item_qty
    $item_description
    $item_price

    I get the following:

    For $item_qty: item1_qty, item2_qty, etc.
    For $item_description: item1_description, item2_description, etc.
    For $item_price: item1_price, item2_price, etc.

    Same thing for plain text email.

    My PHP knowledge is quite limited, and please excuse me if this has been covered elsewhere. I have searched the forums and found similar queries to mine that have used str_replace(). My attempts to use this have failed and result in errors.

    My latest attempt is as follows:

    Last line of $FILTERS = array:
    "comma"=>"$REAL_DOCUMENT_ROOT/formmail_comma_filter.inc.php")

    hidden fields are:
    <input type="hidden" name="filter" value="comma" />
    <input type="hidden" name="filter_fields" value="item_qty, item_description, item_price" />

    Where "formmail_comma_filter.inc.php" contents are:

    $item_qty = $aCleanedValues["item_qty"];
    $item_description = $aCleanedValues["item_description"];
    $item_price = $aCleanedValues["item_price"];

    $subject = array("$item_qty", "$item_description", "$item_price");

    $str= str_replace(",", "<br>", "$subject");

    (wrapped in php tags; though I have also tried without php tags).

    Resulting error:

    filter_failed
    *****/path/to/site/formmail_comma_filter.inc.php: line 1: ?php: No such file or directory
    /path/to/site/formmail_comma_filter.inc.php: line 3: =: command not found
    /path/to/site/formmail_comma_filter.inc.php: line 4: =: command not found
    /path/to/site/formmail_comma_filter.inc.php: line 5: =: command not found
    /path/to/site/formmail_comma_filter.inc.php: line 7: syntax error near unexpected token `('
    /path/to/site/formmail_comma_filter.inc.php: line 7: `$subject = array("$item_qty", "$item_description", "$item_price");'
    *****
    Error=Filter "comma" failed (status 2):

    This is probably something quite simple, but my limited PHP is preventing me to find a solution.

    Any help with this will be greatly appreciated.

    Many thanks in advance.
    Last edited by DamianAU; 09-May-2011 at 05:59 AM.

  2. #2
    Join Date
    May 2008
    Posts
    1,291

    Default Re: Replace ',' with '<br>' or similar for html template

    Hi,

    Normally you'd use "template_list_sep" to specify how lists of values are displayed, if other than the default which is a comma:

    HTML Code:
    <input type="hidden" name="template_list_sep" value="<br>">
    ginger

  3. #3
    Join Date
    May 2011
    Posts
    7

    Default Re: Replace ',' with '<br>' or similar for html template

    Hi Ginger,

    Thanks so much for the quick reply.

    Wow, I completely missed that in the docs!!

    When I try it though, it places <br> in the email, it doesn't actually create a break. It seems to be encoding the value; &lt;br&gt; is what I see in the email source.

    I have tried with and without CharSet=utf-8; and I have the following set in formmail.php: define("BODY_LF","\n");. If I use \r\n the email just shows the html code as text.

    Have I missed something else??

    Thanks.

  4. #4
    Join Date
    May 2008
    Posts
    1,291

    Default Re: Replace ',' with '<br>' or similar for html template

    Hi,

    The only other setting I know of would be:

    Code:
    define("HEAD_CRLF","\n");

  5. #5
    Join Date
    May 2011
    Posts
    7

    Default Re: Replace ',' with '<br>' or similar for html template

    Hi Ginger,

    Sorry, I forgot about that setting (it was very late in the evening here when I replied).

    I am using: define("HEAD_CRLF","\n");

    Using define("HEAD_CRLF","\r\n"); I get html code as text. It also shows me Content-Type: text/html; charset=ISO-8859-1 even though I have specified CharSet=utf-8.

    I had this problem a while ago, but searching forums I found that it was because I'm using postfix to send mail, so I changed to "\n".

    This is quite frustrating as I have seen posts where you have helped other people with the same settings you have given me, and they say it's working for them now.

    I have also tried using a plain text template using "\n" for template_list_sep, but I get \n appearing in the email as text.

    I seem to be going around in circles.

    Is there a way to not encode html entities for specified fields?
    Last edited by DamianAU; 10-May-2011 at 02:01 AM.

  6. #6
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Replace ',' with '<br>' or similar for html template

    Hi,

    The template_list_sep feature can't include HTML code for security reasons.

    Also, HEAD_CRLF and BODY_LF aren't for this purpose, so don't change them as they can break the email completely.

    There's currently no way to add line breaks into a list expansion.

    I'd have to spend some time designing and testing a solution for this, so I can't give you an easy or quick answer at this time.

    I think the ideal solution would be a new feature in FormMail to allow this.

    Sorry for the bad news.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  7. #7
    Join Date
    May 2008
    Posts
    1,291

    Default Re: Replace ',' with '<br>' or similar for html template

    Sorry for misleading you Damian.

    Russell, is this something that was changed in a later version? I could have sworn I'd used the break tag as a list separator before, and I'm sure I have some scripts that haven't been updated in quite a while.

    ginger

  8. #8
    Join Date
    May 2011
    Posts
    7

    Default Re: Replace ',' with '<br>' or similar for html template

    Hi Russell and Ginger,

    Yes, I was about to ask the same question; there is a post from Russel in another forum post which states to use a <br /> in template_list_sep.

    See thread:
    http://www.tectite.com/vbforums/show...plate_list_sep

  9. #9
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Replace ',' with '<br>' or similar for html template

    Hi,

    You're right!

    It changed in version 8.23 as part of a code improvement that fixed a number of bugs.

    I didn't notice the effect of this until now, but the new code is secure, so I can't simply reverse the change.

    Before version 8.23, for example, an attacker could submit a complex set of javascript in your "template_list_sep", and the resulting email could potentially compromise you in some way. An unlikely risk, but a risk nonetheless.

    A basic security principle is that if information is submitted from the web, it *must* be cleaned and/or encoded in such a way that arbitrary logic cannot be included.

    This old feature of template_list_sep is important, and now that it doesn't work I'll have to find a workaround for you.

    I'll post back shortly.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  10. #10
    Join Date
    May 2011
    Posts
    7

    Default Re: Replace ',' with '<br>' or similar for html template

    Hi Russell,

    Oh, thanks so much. You have given me a light at the end of a dark tunnel. The idea I would have to use another processor, or create one was truly not what I wanted at all. I found formmail about 2 years ago, and have been using it and recommending it to people ever since. The main reason for using it is attack/spam prevention without captcha (I really don't like captcha).

    I had a colleague of mine write a hook script (php) which puts html into the email template, but it also becomes encoded. I would be happy to email you the script and any other html files that you might like regarding the order form. I can't post the code here as it's still in production.

    I wasn't aware of your paid support, so from now on, when if I need formmail for complex project requirements, I can make room in the budget for any paid support. What are your prices? Do you have set rates?

    Thanks agan Russell.

    Kind Regards,
    Damian

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem loading HTML Error Template
    By Webz in forum FormMail Subscription Support
    Replies: 3
    Last Post: 26-Feb-2005, 08:50 PM
  2. HTML Template for Email could not be opened
    By gaso in forum FormMail Subscription Support
    Replies: 5
    Last Post: 11-Jan-2005, 11:53 PM
  3. Problem with HTML template
    By bmollon in forum FormMail Subscription Support
    Replies: 4
    Last Post: 25-Nov-2004, 10:46 PM
  4. External CSS Formatting of HTML Email Template
    By sebestyen in forum FormMail Subscription Support
    Replies: 2
    Last Post: 14-Oct-2004, 09:30 PM
  5. Subject=<no subject>?
    By Thomas in forum FormMail Subscription Support
    Replies: 2
    Last Post: 14-Jun-2004, 10:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •