Forums

Fatal error: Cannot use object of type JParameter as array

dksf 14 May, 2014
I have a form which I've setup to conditionally send out an email based on a field value and then process with additional custom code (#4).

The On Submit events are
1. Load User Info [GH]
2. Data To Session
3. Email [GH] - Condition = {status}::OFF
4. Custom Code
<?
    //echo "<LI>HEX".$hex_string;
    function strToHex($string){
        $hex = '';
        for ($i=0; $i<strlen($string); $i++){
            $ord = ord($string[$i]);
            $hexCode = dechex($ord);
            $hex .= substr('0'.$hexCode, -2);
        }
        return strToUpper($hex);
    }
    if($_POST['status'] == 'ON')
    {
    $sso_string = "SML".$_POST['MembershipID']."X".$_POST['ClientID']."EL";
    $hex_string = strToHex($sso_string);
    header('Location: https://mysite.com/?ocx='.$hex_string);
    }
    else{
    while(list($key, $value) = each($_POST))
    {
    if(!empty($value))$params[$key] = $value;
    }


Theres more to the code but it keeps breaking at line 21

My code works when if($_POST['status'] == 'ON')

If the status is 'OFF' My conditional email is sent out and I get the following error:

Fatal error: Cannot use object of type JParameter as array in /var/www/vhosts/mysite.com/httpdocs/administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(19) : eval()'d code on line 21

Line 21 = if(!empty($value))$params[$key] = $value;

I can use the curl action and post my form to an external file with the same code thats in my custom code action (#4) and it works (no emails are sent though).

Does anyone have any suggestions on what the issue is? I've read a few posts that seem to point to Joomla and the use of JParameter depreciating.

Thanks
GreyHead 14 May, 2014
Answer
Hi dksf,

The problem is with your line 21
if(!empty($value))$params[$key] = $value;
and, as the message says it's because you are using $params as an array e.g. $params[$key] while it is actually an object so presumably should be $params->$key

The best thing to do is to add a temporary line of debug code to dump out $params and see what is in it.

BUT I don't see what this code is doing? What is $params here?

Bob
dksf 14 May, 2014
Thanks Bob!!

That did the trick. I had been so focused on the conditional email and removing curl that I missed that.
This topic is locked and no more replies can be posted.