Psyduck - 可達鴨 之 鴨力山大 v0.1

Current Path : home/irplbiz/public_html/demo_dev/demo_crm4/
Upload File :
Current File : /home/irplbiz/public_html/demo_dev/demo_crm4/submit_form.php

<?php
// Read form data
$firstName = $_POST['first_name'];
$lastName = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];

// API URL for SuiteCRM instance
$apiUrl = 'https://orionedutech.co.in/suite/service/v4_1/rest.php';

// API Authentication (Login or OAuth)
$authData = array(
    'user_auth' => array(
        'user_name' => 'manjari', // SuiteCRM username
        'password' => md5('manjari'), // SuiteCRM password (hashed with MD5)
		//'password' => 'manjari', // SuiteCRM password (hashed with MD5)
    ),
    'application_name' => 'PHP Contact Form Integration',
);

// Get the session ID for the authenticated user
$authPayload = json_encode(array(
    'method' => 'login',
    'input_type' => 'JSON',
    'response_type' => 'JSON',
    'rest_data' => json_encode($authData),
));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $authPayload);

$response = curl_exec($ch);
curl_close($ch);

$responseData = json_decode($response, true);
$sessionId = $responseData['id'];

// Create a new contact record in SuiteCRM
$contactData = array(
    'session' => $sessionId,
    'module_name' => 'Leads',
    'name_value_list' => array(
        array('name' => 'first_name', 'value' => $firstName),
        array('name' => 'last_name', 'value' => $lastName),
        array('name' => 'email1', 'value' => $email),
        array('name' => 'phone_work', 'value' => $phone),
        array('name' => 'description', 'value' => $message),
    ),
);

$contactPayload = json_encode(array(
    'method' => 'set_entry',
    'input_type' => 'JSON',
    'response_type' => 'JSON',
    'rest_data' => json_encode($contactData),
));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $contactPayload);

$response = curl_exec($ch);
curl_close($ch);

// Check the response
$responseData = json_decode($response, true);

if (isset($responseData['id'])) {
    echo "Contact submitted successfully!";
} else {
    echo "Error submitting contact: " . $responseData['error']['name'];
}
?>