TOPIC:

API call 1 year 3 months ago #242321

  • Topic Author
  • gtgt
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 64
  • Thanks: 1
Hi,

I would like to create an API call from the data of a form created withbreezing form.

After pressing the submit button I would like to send an API call with the data (value) of form elements.
The answer would be Yes or No.
I would like to display teh Yes/No answer somehow.

Is it possible to manage it if I add some script into the advanced options, submit pieces part?

Thanks in advance.

Tamas

Please Log in or Create an account to join the conversation.

API call 1 year 3 months ago #242324

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
Hi,

not sure if I understand the direction:

Do you want to send the form data to some API or do you want to pull the data from somewhere and display it before submit?

You were talking on pressing submit but then about displaying something at the same time, so I am not sure about the workflow you need.

Regards,
Markus

Please Log in or Create an account to join the conversation.

API call 1 year 3 months ago #242347

  • Topic Author
  • gtgt
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 64
  • Thanks: 1
I would like to send.

Please Log in or Create an account to join the conversation.

API call 1 year 3 months ago #242353

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
Hi,

alright. You have several options here.
I assume this is a rest api call.

If it is I would suggest to use an end submit piece (=PHP) and forward the desired data using curl, performing the API call (usually a post).

Here a general example addressing an imaginery rest service.
It assumes the data needs to be sent to the rest api service json encoded.
It will depend on the actual API you are targeting if you actually need this or not, but this is a common procedure:
// loading the BreezingForms API, mostly for using ff_getSubmit
$this->execPieceByName('ff_InitLib');

/**
   This is an example cURL rest api call from:
   https://tutorialsclass.com/php-rest-api-post-data-using-curl/
*/

// User data to send using HTTP POST method in curl

// data taken from the form:

$data = array('name'=>ff_getSubmit("name"),'salary'=>ff_getSubmit("salary"), 'age' => ff_getSubmit("age"));

// Data should be passed as json format
$data_json = json_encode($data);

// API URL to send data
$url = 'http://dummy.restapiexample.com/api/v1/create';

// curl initiate
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

// SET Method as a POST
curl_setopt($ch, CURLOPT_POST, 1);

// Pass user data in POST command
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

// Execute curl and assign returned data
$response  = curl_exec($ch);

// Close curl
curl_close($ch);

// See response if data is posted successfully or any error
// for debugging remove the comments
//print_r ($response);
//exit;

This could would need to be adjusted, matching your form elements. Basically changing the field names (not titles) in ff_getSubmit() calls and likely adding a few more, depending what you need to send.

In the end, the code would need to go into form => advanced => more options => submit pieces => end submit => click "custom".

Please let me know if this is what you are looking for.

Regards,
Markus

Please Log in or Create an account to join the conversation.

Last edit: Post by TheMuffinMan.

API call 1 year 2 months ago #243901

  • SHADOWSKY
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 38
  • Thanks: 0
I get an error when using this script:
syntax error, unexpected '_ff_traceExit' (T_STRING), expecting ')'

I want to use this script to submit a trace ID to an API endpoint and display the JSON object response on the page which displays multiple fields.

Please Log in or Create an account to join the conversation.

API call 1 year 2 months ago #243910

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
Hi,

can you please post the current state of your code?
The above simply says there is a syntax error.

When you post the code, please use the forum's code tags.

Regards,
Markus

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.054 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!