1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

\n in php form

Discussion in 'Plugins' started by calmdevil, May 9, 2011.

  1. calmdevil

    calmdevil Member

    Level: Community
    Hello,
    I have a problem with email form in php.
    I use a form like:
    PHP:
    $to  = "He;test@example.com>, " ;
    $subject = "Test subj";
    $message = 'test';
    $headers  = "Content-type: text/html; charset=UTF-8 \r\n";
    $headers .= "From: Me <test1@example.com>\r\n";
    mail($to, $subject, $message, $headers);
    Just after saving all content of form below first "\n" disappers and I got like this:
    PHP:
    $to  = "He;test@example.com>, " ;
    $subject = "Test subj";
    $message = 'test';
    $headers  = "Content-type: text/html; charset=UTF-8 \r
    Have anybody versions: how to solve problem?

    PS
    I can't use sendmail plugin - argument $to is needed to get from MySQL query.
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I'll see if I can work out what is chomping your code. Are you using the PHP form submission plugin?

    Meanwhile - you should be able to use the standard email plugin, as we provide an "Email to (eval)" option, that lets you specify a PHP fragment which returns a comma separated list of addresses to mail to. I added this a while back specifically so you can do things like query other tables for addresses.

    -- hugh
     
  3. calmdevil

    calmdevil Member

    Level: Community
    Yes, I think an "Email to (eval)" option is a good, but I need to make query by ID and need in some operators to get string with email:
    PHP:
    $toclient = mysql_query("SELECT email FROM `clients` WHERE id='{test___sname_raw}'");
    $to=mysql_fetch_row($toclient);
    $to=$to[0];
    echo $to;
    but its not work in "Email to (eval)".
    So I must rebuild database to exchange ID to username or make workable this option.
     
  4. calmdevil

    calmdevil Member

    Level: Community
    Ok, I got it :)
    PHP:
    $toclient = mysql_query("SELECT email FROM `clients` WHERE id='{test___sname_raw}'");
    $to=mysql_fetch_row($toclient);
    $to=$to[0];
    return $to;
    Thank you!!!

    But, why so strange behavior in "Run PHP" plugin? It's only for interest: why script is cutted down after "\n", including it?
     
  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I don't know. It's something to do with the way J! filters the param settings when saving. I thought it was something we'd fixed a while back, but obviously not.

    BTW, probably better to use J!'s database API, so you can easily sanitize your inputs, and J! will know to pitch informative error messages when in debug mode:

    PHP:
    $db =& JFactory::getDBO();
    $db->setQuery("SELECT email FROM `clients` WHERE id=" . $db->Quote('{test___sname_raw}'));
    return $db->loadResult();
    -- hugh
     
  6. rob

    rob Administrator Staff Member

    Level: Community
    yeah \n is Joomla1.5 means 'start a new name/pair value of parameter options, so putting \n in your code can cause all sorts of mischief
    J1.6 stores things as json which is a lot more robust and will resolve issues such as this
     
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I thought we'd found at least a workaround for this?

    Maybe the 'tohere' block approach works, i.e. ...

    PHP:
    $foo = <<< EOT
    Line 1
    Line 2
    EOT
    ;
    -- hugh
     
  8. rob

    rob Administrator Staff Member

    Level: Community
    solution was to remove them I believe!
    -Rob
     
  9. iztokz

    iztokz Member

    Level: Community
    I assume I have a related issue to report. I was working with form view and form details.

    I was also trying to use \n and it eats away my code. So I tried using <br> and <b></b> in php calc plugin. Results are correctly displayed in from/data view in fabrik admin backend, but on fronted code and text in feld comment got cut on the first instance where using html tags.

    I have attached two images, how I can view comment which is result of php calc pluggin.

    What I am trying to do is add some basic styling to the comment, but nothing what I have tried works in front end, while in backend and dB everything is displayed correctly.

    I am using Fabrik 2 SVN, revison 5701
    J 1.5.23, php 5.3.8.

    And then I tried a little workourund, using fabrik content plugin, to call the specific element in question and display it in article, and my comment is shown with all the styling. So it seems that form details view in frontend has the issue. I tried embeding form via fabrik plugin in article and also tested via fabrik menu item and it's the same issue un both instances.
     

    Attached Files:

  10. iztokz

    iztokz Member

    Level: Community
    friendly bump :)
     

Share This Page