[SOLVED] Php changes incompatible with existing code?

Some php in my forms no more works.

For example, in PHP Form Plugin, no more works
PHP:
jimport('joomla.filesystem.file');
$id_nominativo = $formModel->formData[id];

I changed in
PHP:
$id = $formModel->getElementData('fabrik_nominativi___id');
$id_nominativo = (int)$id;
It works; but I have to change my code in all PHP Form Plugin.

Also doesn't work PHP called by JavaScript using Ajax.
At the moment I don't know why.

Ok, I hope to discover what I have to change, but I have to check all my code; it requires a lot of time and there is the risk I don't discover all malfunctions.

Ok, I have to do this work, but where can I read what is changed, to save time?


An additional issue: I have just updated by Github; now the box of PHP code is very narrow:
1.png
 
I can't imagine that
$id_nominativo = $formModel->formData[id];
was working, it must be
$id_nominativo = $formModel->formData['id'];
 
At least $id_nominativo = $formModel->formData[id]; will throw a warning (Notice: Use of undefined constant id- assumed 'id') which may break Ajax.
Maybe you had Joomla error reporting = none before and = max now.

I can confirm the small editor window.
 
troester is entirely correct. Code which throws notices or warnings will break any AJAX calls, if you have error reporting enabled, because the PHP notice gets rendered in the response ahead of the JSON, which then causes the JS's JSON.decode() to puke. So the code may run and work (in this case PHP just assumed you meant 'id', which is correct, so the code works) if you have error reporting off, or set to exclude notices and warnings, but will cause the Javascript to fail if you have notices and warnings being reported.

I also noticed the small PHP box as of a few days ago, I'll see if I can track that one down.

-- hugh
 
troester
Yes, I confirm
- some time ago I modified the settings to Fabrik debug = yes.
- I got a message like undefined constant id - assumed 'id'

troester and hugh (hi)
I have justed set Fabrik debug = no and tried again, but Ajax method don't work.
I use Ajax to inquire and modify database and send email.

There is also something else strange:
$destinatari_Cc = 'Sede appartenenza ' . $Sede_di_Appartenenza . ' ' . '<' . $Email_Sede_Appartenenza . '>';
doesn't works (I tried also ").
I think it depends on < or/and >.

But, in the past worked well the code
$Email_Sede_Appartenenza = "Sede " . $Sede_di_Appartenenza . " " . "<" . $Email_Sede_Appartenenza . ">";
in PHP Form Plugin in an other form.

2.png


I am confused... o_O
 
Error messages have nothing to do with Fabrik debug, it's the Joomla "Error Reporting" setting in "Global configuration/Server".

php form plugins:
You can put
var_dump($destinatari_Cc,$Sede_di_Appartenenza,$Email_Sede_Appartenenza );exit;
in your php code to see what you really get.

If this is with an ajaxfied form you have to inspect the network response to get the var_dump output.
 
Before post my question, I tried var_dump() and echo.
Assuming $Sede_di_Appartenenza="Nord-est",

$destinatari_Cc = "Sede appartenenza " . $Sede_di_Appartenenza . " " . "<" . $Email_Sede_Appartenenza . ">";
var_dump($destinatari_Cc);
echo "<br />"; I got: Sede appartenenza Nord-est
echo "<" . $Email_Sede_Appartenenza . ">" . "<br />"; I got a blank line
exit;

In the past (at least until 30/03/15) mails were send:
index.php



I do not know when issues of PHP Form Plugin and Ajax started (I was engaged in scheduled tasks from the beginning of April).
I updated from Github on 2015-04-04, 2015-04-07, 2015-04-16 and 2015-04-26.
 
How do you set $Email_Sede_Appartenenza?

Set Joomla's error reporting to max
Try with var_dump, NOT echo
 
I just tried
PHP:
var_dump($Sede_di_Appartenenza);
echo "<br />";
 
$destinatari_Cc = "Sede appartenenza " . $Sede_di_Appartenenza;
 
var_dump($destinatari_Cc);
echo "<br />";
 
var_dump($Email_Sede_Appartenenza);
echo "<br />";
 
  $destinatari_Cc .= " " . "<" . $Email_Sede_Appartenenza . ">";
 
  echo " " . "<" . $Email_Sede_Appartenenza . ">";
  echo "<br />";
 
var_dump($destinatari_Cc);
echo "<br />";
echo "-----";
exit;

The result is
string(10) "Nord-ovest"
string(28) "Sede appartenenza Nord-ovest"
string(22) "f.schettino@tiscali.it"

string(53) "Sede appartenenza Nord-ovest "
-----


I am disheartened.
 
I need use php statement
mail($to, $subject , $message, $additional_headers);
in which I need, for example,
Sede appartenenza Nord-ovest<email address>
in $additional_headers.

Since PHP Form Plugin no more works, I was engaged to understand why it don't works; I got the error so I thought I needed to solve this.
So, If I understand correctly, I can ignore this problem and go forward to search; is it true?


Regarding php code used in Ajax method, in the past the following code worked well
PHP:
$db = JFactory::getDBO();
$nome = JRequest::getVar('nome', '');
$cognome = JRequest::getVar('cognome', '');
$nome_cognome = $nome . " " . $cognome;
but now no more works.

I tried
PHP:
        $app = JFactory::getApplication();
        $input = $app->input;
     
        $nome = $input->getString('nome', '');
        $cognome = $input->getString('cognome', '');
        $indirizzo_email = $input->getString('indirizzo_email', '');
It works.

I don't understand what happened; why my old code no more works???
 
JRequest is deprecated (this is Joomla).

No idea what "mail" needs, it may depend on your mail settings in Joomla configuration.
Better use the Joomla JFactory::getMailer();
 
Yes, I red in J! log that JRequest is deprecated; the same JApplication, JHtml::getJSObject, JDispatcher, JError::getErrors().

But I use statements because I red about them in Fabrik Wiki or Fabrik Forum (I never used php before use Fabrik); probably I red an oldWiki/thread.

The only exception is for mail; I didn't know JFactory::getMailer();, but mail worked in the past.
I will read documentation about JFactory::getMailer(); and I will substitute it to mail.
 
I need help!
I am not able to understand why mails are not sent from user_ajax.php.

I verified
- Mass Mail and Scheduled tasks/email plugin work (they send email)
- no email in spam.


I tried (it worked in the past):
PHP:
$messaggio = "Corpo del messaggio.";
$destinatari = "f.schettino@inwind.it";
$mittente = "non_rispondere@lavoro-over40.com";
 
$intestazioni  = "MIME-Version: 1.0" . "\r\n";
$intestazioni .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$intestazioni .= 'From: Sito Associazione Lavoro Over 40 <non_rispondere@lavoro-over40.com>' . "\r\n";
$intestazioni .= "Reply-To: <non_rispondere@lavoro-over40.com>" . "\r\n";
 
$ret = mail($destinatari, $oggetto, $messaggio, $intestazioni);
I used echo and var_dump to verify.
All seems right; $ret returns true.


I tried also (your suggestion):
PHP:
$messaggio = "Corpo del messaggio.";
$destinatari = "f.schettino@inwind.it";
$mittente = "non_rispondere@lavoro-over40.com";
 
$mailer = JFactory::getMailer();
 
$mailer->setSender($mittente);
$mailer->setSubject($oggetto);
$mailer->setBody($messaggio);
 
$mailer->send();
I don't know how check if the mail is sent (equivalent to $ret = mail).
 
I am a stupid man, sorry.
Now it works; thank you troester!

So I have to change all occurrences of
- from mail(...); to JFactory::getMailer();
- from​
jimport('joomla.filesystem.file');
$id=$formModel->formData['id'];
to​
$id=$formModel->getElementData('fabrik_xxx___id');
- from​
$aaa= JRequest::getVar('aaa','');
to​
$app= JFactory::getApplication();
$input=$app->input;
$aaa =$input->getString('aaa','');

I think that all my problems was due to new J! (something no more works); do you agree?
I hope that I will have no more problems.
 
The JRequest API usually still works, although it has been deprecated and may disappear soon, but yes, you should use the new JInput stuff instead ($input).

With regards to using getElementData() instead of accessing the model's formData[] array directly, again ... yes, that's the best way. The formData array will (almost) always have what you want, but sometimes elements are keyed by full name (table___name), and sometimes just name. We strip off the table___ when we actually write the data out to the database, so from 'onAfterProcess' onwards in the processing cycle. But the getElementData() function takes that in to account, and should always work when given a full (table___name) name.

-- hugh
 
Hi, hugh.
Thanks for the confirmation and explanation.

Could it be that my problems depends on J! 3.4.1 but I realize only now because I was busy in another job?

It is very frustrating and discouraging:confused: when parts that worked no longer worko_O ; it requires a lot of time to understand "why" it happens and "how" modify.
Fortunately I have the huge help of all of you :) (and I am hardheaded).
 
Please, some last questions. Thanks in advance.
I didn't get information in https://docs.joomla.org/Sending_email_from_extensions or using Google.

1- Unfortunately, the php statement mail() no more works.
I used​
$to = $riga['Nome'] . " " . $riga['Cognome'];
$to .= " <" . $riga['E_mail'] . ">"
(You know that it displays something like Franco Ciccio the email address is not displayed)​

How can fill the array $to to get the same using $mailer->addRecipient($to); ?​
2- How I can test that the email is sent, using JFactory::getMailer();?
Using mail() I could write $xxx =mail(); and test if $xxx is true or false.​

3- I know that it is possible use
$mailer->addBCC("blindcopy@yourdomain.com");​
to insert addresses in BCc​
What is the statement to insert addresses in Cc? (not blindcopy)​
$mailer->addCC ???​


Franco
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top