Forums

Error 403 on submit

tshirley 23 Aug, 2016
Hi,

I have been trying to use an API to interface CF5 to Salesforce. I successfully authenticate and retrieve data using curl in custom code, but I get a 403 error when saving the form - however if I save a second time it works.

And when I test the form the code works - I can see successful results in a Debugger - but when I try to submit the form (with nothing in the submit event except a display message) I get an error 403 again.

My Joomla install is standard, so I tried turning off the Error reporting in the Global configuration however that made no difference.

If I take out the API custom code the form works.

So I am confused. I don't understand why the save doesn't work every time, and - since the API code works - I don't know why a simple url like:

http://www.mysite.org/index.php?option=com_chronoforms5&chronoform=testrest&event=submit

will give a 403. I am a logged in administrator of this site😟

Any ideas gratefully accepted.

Cheers

Tim
GreyHead 23 Aug, 2016
Hi Tim.

Looks like there is some problem with the API code that is throwing a PHP Error - in current Joomla! versions that can give a 403 Error. Try setting site debugging to Maximum and see if you get anything more helpful. Otherwise it usually seems to end up as a line by line debugging job - comment everything out, uncomment a few lines and test.

Bob
tshirley 23 Aug, 2016
Thanks Bob,

I have managed to clear the error 403 on save, and I have eliminated all errors that showed up when I set "Development" mode in Joomla. None of these errors were causing the code to fail when run.

I separated out the API code which retrieved SF data into a separate Custom Code element, the authentication code in another. The query code is this:


<?php

//
//  search for Club Names and Membership Numbers
//

$bearer =  "Authorization : Bearer ".$form->data['access'];

$hdrfields = array();
$hdrfields[] = $bearer;
$hdrfields[] = "Content-Type: application/x-www-form-urlencoded";	

$form->data['hdrfields'] = $hdrfields;			   

$url = "https://ap4.salesforce.com/services/data/v".$form->data['latestversion'];

$q = "/query/?q=SELECT+Display_Name__c,Member_Nbr__c+from+Contact+WHERE+Membership_Type_L__c='Club'+AND+Status_L__c='Active'+ORDER+BY+Display_Name__c";

$url2 = $url.$q;

$form->data['url2'] = $url2;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_HTTPHEADER, $hdrfields);
curl_setopt($ch, CURLOPT_GET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response2  = curl_exec($ch);
curl_close($ch);

$form->data['contactfields'] = json_decode($response2, true);
$form->data['C'] = $form->data['contactfields']['records'];

?>



This code works and delivers the data as expected, and I am populating a Dynamic Dropdown list. However then the Submit button gives error 403. The url on the submit looks perfectly normal.

When I completely delete this Custom Code element the Submit button works and there is no error, but I get no data of course. I have tried various commenting out, but even with the curl completely removed it still gives error 403 when I click Submit.

So I am a bit unsure how to proceed.

Cheers

Tim
This topic is locked and no more replies can be posted.