GET name attributes sent using API


#1

I’m so close into getting the API to work correctly with a Virtuagym enrollment form.

I just cant seem to link the HTML ´name´ attibutes I gave each input field to get sent through my API.

My question basically is: why does this work:

$fname = "John"; 
$lname = "Doe";
$email = "hi@mail.com"; 

But doesnt this work:

$fname = $_GET['roepnaam']; 
$lname = $_GET['last_name'];
$email = $_GET['e-mail'];

The names inside the brackets are the names in the HTML field names.

I have no clue what should be filled after $fname = … Please advice.

Complete API (fake keys etc) as shown below.

<?php

define('API_URL', 'https://virtuagym.com/api/v1/'); 
define('API_KEY', 'MzuwtwgsAEXhNglVc0I7zVUWju1INauUwiV62XXX1rt'); 
define('CLUB_ID', '12521'); 
define('CLUB_KEY', 'CS-12521-ACCESS-7ilUAlrEiNC8PbGCylUVf0uXX'); 

$fname = $_GET['roepnaam']; 
$lname = $_GET['last_name']; 
$mail= $_GET['e-mail']; 

$customer_data = array( 
    "firstname" => $fname, 
    "lastname" => $lname, 
    "email" => $mail,
); 

$data_string = json_encode($customer_data); 
 
$url = API_URL.'club/'.CLUB_ID.'/member?api_key='.API_KEY.'&club_secret='.CLUB_KEY; 
$ch = curl_init($url); 
curl_setopt_array($ch, array( 
        CURLOPT_CUSTOMREQUEST => 'PUT', 
        CURLOPT_POSTFIELDS => $data_string, 
        CURLOPT_RETURNTRANSFER => true, 
        CURLOPT_SSL_VERIFYPEER => false // not the best way, but it works (might want to validate the certificate) 
    ) 
); 
$result = curl_exec($ch); 
curl_close($ch); 
 
$response = json_decode($result); 
 
echo 'Response: <br /><br />'; 
echo '<pre>'; 
var_dump($response); 
echo '</pre>'; 

get_footer(); ?>

Thank you!