prepare('SELECT email FROM clients WHERE id = ?'); $stmt->execute([$client_id]); $client = $stmt->fetch(); if (!$client) { // Client not found header('Location: dashboard.php'); exit; } // Fetch the latest contract $stmt = db()->query('SELECT * FROM contracts ORDER BY created_at DESC LIMIT 1'); $contract = $stmt->fetch(); if (!$contract) { // No contract found, so redirect to dashboard header('Location: dashboard.php'); exit; } try { $submission = $docuseal->submissions->create([ 'template_id' => DOCUSEAL_TEMPLATE_ID, 'submitters' => [ [ 'email' => $client['email'], 'role' => $contract['role'] ] ], 'custom_fields' => [ ['name' => 'contract_content', 'value' => $contract['content']] ] ]); // Store the submission ID $stmt = db()->prepare('INSERT INTO client_contracts (client_id, contract_id, docuseal_submission_id) VALUES (?, ?, ?)'); $stmt->execute([$client_id, $contract['id'], $submission['id']]); } catch (Exception $e) { // Handle API errors echo 'Error creating DocuSeal submission: ' . $e->getMessage(); exit; } ?>
Please review and sign the following contract to complete your registration.