Passing message through loop | 0 - syntax error, unexpected 'test' (T_STRING)

SoilentRed

Caaan do!
I have a form with a textarea element. This element gets formatted and passed through a loop and inserted into a few rows. It works perfectly fine except when the submitter presses [Enter] to start a new line in their message. When the submitter has a new line in their message, I get the following error:

Code:
0 - syntax error, unexpected 'test' (T_STRING)

Here's is the OnAfterProcess php plugin code I'm running
Code:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery( true );
$selection = '{sms___which_groups_raw}';
$sels = explode( ",", $selection );
$bad_symbols = array( ",", ".", "-", " " );
$timezone = '{sms___tz}';
$scheduledDateTime = $formModel->getElementData('sms___scheduled_datetime');
$scheduledDateTime = new DateTime($scheduledDateTime);
// $list = array();
// start building the query ..
$myQuery->insert( 'afab_smsq' );
$myQuery->columns(
  array(
    $myDb->quoteName( 'date_time' ),
    $myDb->quoteName( 'f_name' ),
    $myDb->quoteName( 'l_name' ),
    $myDb->quoteName( 'full_name' ),
    $myDb->quoteName( 'message' ),
    $myDb->quoteName( 'scheduled_datetime' ),
    $myDb->quoteName( 'company' ),
    $myDb->quoteName( 'subject' ),
    $myDb->quoteName( 'agent_id' ),
    $myDb->quoteName( 'mobile' ),
    $myDb->quoteName( 'status' )
  )
);
foreach ( $sels as $sel ) {
$scheduled = 'CONVERT_TZ(' . $myDb->quote($scheduledDateTime->format('Y-m-d H:i:s')) . ', "+0:00", "'.$timezone.'")';
  $insel = ( int )$sel;
  $myDb->setQuery( 'SELECT cell_phone, userid, name, first_name, last_name, organization FROM #__acymailing_subscriber JOIN #__acymailing_listsub ON #__acymailing_subscriber.subid = #__acymailing_listsub.subid WHERE #__acymailing_listsub.listid = ' . $insel . ' AND #__acymailing_subscriber.enabled = 1' );
  $rows = $myDb->loadObjectList();
  foreach ( $rows as $row ) {
    $cellphone = str_replace( $bad_symbols, "", $row->cell_phone );
    if ( empty( $cellphone ) ) {
    } else {

      $myQuery->values(
        implode( ',',
          array(
            $myDb->quote( '{sms___date_time}' ),
            $myDb->quote($row->first_name),
            $myDb->quote($row->last_name),
            $myDb->quote($row->name),
            $myDb->quote(html_entity_decode( '{sms___message}', ENT_QUOTES | ENT_XML1, 'UTF-8') ),
            $scheduled,
            $myDb->quote($row->organization),
            $myDb->quote( '{sms___subject}' ),
            $myDb->quote( '{sms___nia_agent_id}' ),
            $myDb->quote($cellphone),
            0
          )
        )
      );
    }
  }
}
  // run the query
  $myDb->setQuery( $myQuery );
  // uncomment this line if you need to debug
  // var_dump($myQuery);exit;
  $myDb->execute();

It looks like the message gets submitted successfully in all cases to the SMS table, but not the SMSQ table that it's supposed to loop through.

I need to use the ENT_QUOTES decoder because it was converting all my special characters. for example, the "&" symbol was being converted to "&". But I also need to be able to insert a new line in the textarea without it breaking.

Help and guidance are always valued.
 
Friendly Bump.
giphy.gif
 
There's no 'test' in your code, so the error is not related to it.
Or you have some unbalanced quotes or some unquoted placeholder somewhere.
 
There are quirks in the code, at least in the query, and particularly for the columns: either you build the array outside the query and implode it inside the query, or you simply make it that comma-separated list of column names inside the query.
Technically ok, but completely unnecessary: the values method. You're building an array, only to implode it immediately again - all on the same line. Why not make it just a comma-separated list to start with...
https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase

There might be more, but once you've fixed the columns issue (and perhaps cleaned up and re-structured the code, also for better readability), you should be at least much closer to the finish line.
 
Last edited:
@troester , 'test' was part of what was submitted in the textarea.
something like
Code:
test this is a test
test i repeat this is a test.

@lousyfool
either you build the array outside the query and implode it inside the query
Why not make it just a comma-separated list to start with...
This route looks like it may be my only course of action. I was hoping it was really just a syntax thing I could nip in the butt. Thank you.
 
html_entity_decode( '{sms___message}', ENT_QUOTES | ENT_XML1, 'UTF-8')

I would debug this outside your loop/query.... I don't know if your newline is \n\r or <br> or ... and what html_entity_decode is doing with it. Maybe you have to do some more string handling to get what you need.
 
I'm noticing now that even when I put the element outside the loop it has the same behavior.
Code:
$outsideLoop = '{sms___message}';
when the element contains one line, for example:
Code:
this is all on one line
a vardump on $outsideLoop returns
Code:
C:\wamp64\www\nia\plugins\fabrik_form\php\php.php(557) : eval()'d code:80:string 'this is all on one line' (length=23)
good.
BUT, when I have a message with multiple lines like
Code:
this is all on
two lines
a vardump on $outsideLoop returns
Code:
0 - syntax error, unexpected 'lines' (T_STRING)
You may not be able to visit this page because of:

[LIST=1]
[*]an out-of-date bookmark/favourite
[*]a search engine that has an out-of-date listing for this site
[*]a mistyped address
[*]you have no access to this page
[*]The requested resource was not found.
[*]An error has occurred while processing your request.
[/LIST]
Please try one of the following pages:

[LIST]
[*]Home Page
[/LIST]
If difficulties persist, please contact the System Administrator of this site and report the error below.
Bad.
Is it something about the way the textarea element is set up?

I'm going to try to explode the new lines through a loop and insert them as a string. but the more I look at this the more I think something may be off with the element

EDIT: attached are screencaps of my textarea setup
 

Attachments

  • advanced.jpg
    advanced.jpg
    32.9 KB · Views: 100
  • textarea-layout.jpg
    textarea-layout.jpg
    22.9 KB · Views: 107
  • textarea-limit.jpg
    textarea-limit.jpg
    23.8 KB · Views: 116
  • textarea-options.jpg
    textarea-options.jpg
    40.7 KB · Views: 108
  • textarea-tagify.jpg
    textarea-tagify.jpg
    24.4 KB · Views: 92
  • textarea-truncate.jpg
    textarea-truncate.jpg
    32.6 KB · Views: 86
  • textarea-validations.jpg
    textarea-validations.jpg
    55.4 KB · Views: 93
Last edited:
I need some help with this application as it is still wonky.
Problem one: all the aforementioned issues with being unable to write multiple lines.
Problem Two: When texts are passed through twilio, users are getting multiple messages.
If anyone wants to throw in a bid, please let me know.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top