-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturbosign-advanced.php
More file actions
196 lines (175 loc) · 7.89 KB
/
Copy pathturbosign-advanced.php
File metadata and controls
196 lines (175 loc) · 7.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/**
* Example 3: Review Link - Advanced Field Types
*
* This example demonstrates advanced field types and features:
* - Multiple field types: signature, date, text, checkbox, company, title
* - Readonly fields with default values
* - Required fields
* - Multiline text fields
*
* Use this when: You need complex forms with varied input types
*/
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use TurboDocx\TurboSign;
use TurboDocx\Config\HttpClientConfig;
use TurboDocx\Types\Recipient;
use TurboDocx\Types\Field;
use TurboDocx\Types\SignatureFieldType;
use TurboDocx\Types\TemplateConfig;
use TurboDocx\Types\FieldPlacement;
use TurboDocx\Types\FieldMetadata;
use TurboDocx\Types\FieldConditional;
use TurboDocx\Types\ConditionalOperator;
use TurboDocx\Types\ConditionalAction;
use TurboDocx\Types\Requests\CreateSignatureReviewLinkRequest;
function advancedFieldsExample(): void
{
TurboSign::configure(new HttpClientConfig(
apiKey: getenv('TURBODOCX_API_KEY') ?: 'your-api-key-here',
orgId: getenv('TURBODOCX_ORG_ID') ?: 'your-org-id-here',
senderEmail: getenv('TURBODOCX_SENDER_EMAIL') ?: 'support@yourcompany.com',
senderName: getenv('TURBODOCX_SENDER_NAME') ?: 'Your Company Name'
));
try {
$pdfFile = file_get_contents(__DIR__ . '/../../ExampleAssets/advanced-contract.pdf');
echo "Creating review link with advanced field types...\n\n";
$result = TurboSign::createSignatureReviewLink(
new CreateSignatureReviewLinkRequest(
recipients: [
new Recipient('John Doe', 'john@example.com', 1),
],
fields: [
// Signature field
new Field(
type: SignatureFieldType::SIGNATURE,
recipientEmail: 'john@example.com',
template: new TemplateConfig(
anchor: '{signature}',
placement: FieldPlacement::REPLACE,
size: ['width' => 100, 'height' => 30]
)
),
// Date field
new Field(
type: SignatureFieldType::DATE,
recipientEmail: 'john@example.com',
// pins a fixed date in MM/DD/YYYY; omit defaultValue to auto-fill the recipient's signing date
defaultValue: '12/31/2026',
template: new TemplateConfig(
anchor: '{date}',
placement: FieldPlacement::REPLACE,
size: ['width' => 75, 'height' => 30]
)
),
// Full name field
new Field(
type: SignatureFieldType::FULL_NAME,
recipientEmail: 'john@example.com',
template: new TemplateConfig(
anchor: '{printed_name}',
placement: FieldPlacement::REPLACE,
size: ['width' => 100, 'height' => 20]
)
),
// Readonly field with default value (pre-filled)
new Field(
type: SignatureFieldType::COMPANY,
recipientEmail: 'john@example.com',
defaultValue: 'TurboDocx',
isReadonly: true,
template: new TemplateConfig(
anchor: '{company}',
placement: FieldPlacement::REPLACE,
size: ['width' => 100, 'height' => 20]
)
),
// Required checkbox with default checked
new Field(
type: SignatureFieldType::CHECKBOX,
recipientEmail: 'john@example.com',
defaultValue: 'true',
required: true,
template: new TemplateConfig(
anchor: '{terms_checkbox}',
placement: FieldPlacement::REPLACE,
size: ['width' => 20, 'height' => 20]
)
),
// Title field
new Field(
type: SignatureFieldType::TITLE,
recipientEmail: 'john@example.com',
template: new TemplateConfig(
anchor: '{title}',
placement: FieldPlacement::REPLACE,
size: ['width' => 75, 'height' => 30]
)
),
// Multiline text field
new Field(
type: SignatureFieldType::TEXT,
recipientEmail: 'john@example.com',
isMultiline: true,
template: new TemplateConfig(
anchor: '{notes}',
placement: FieldPlacement::REPLACE,
size: ['width' => 200, 'height' => 50]
)
),
// Conditional (IF/THEN) fields
// Controlling checkbox: carries a stable fieldKey that dependents reference
new Field(
type: SignatureFieldType::CHECKBOX,
recipientEmail: 'john@example.com',
template: new TemplateConfig(
anchor: '{request_changes}',
placement: FieldPlacement::REPLACE,
size: ['width' => 20, 'height' => 20]
),
metadata: new FieldMetadata(fieldKey: 'request_changes')
),
// Dependent text field: hidden until the checkbox above is checked ("If checked, explain")
new Field(
type: SignatureFieldType::TEXT,
recipientEmail: 'john@example.com',
isMultiline: true,
template: new TemplateConfig(
anchor: '{change_details}',
placement: FieldPlacement::REPLACE,
size: ['width' => 200, 'height' => 50]
),
metadata: new FieldMetadata(
conditional: new FieldConditional(
controllingFieldKey: 'request_changes',
operator: ConditionalOperator::IS_CHECKED,
action: ConditionalAction::SHOW
)
)
),
],
file: $pdfFile,
documentName: 'Advanced Contract',
documentDescription: 'Contract with advanced signature field features'
)
);
echo "✅ Review link created!\n\n";
echo "Document ID: {$result->documentId}\n";
echo "Status: {$result->status}\n";
echo "Preview URL: {$result->previewUrl}\n";
if ($result->recipients !== null) {
echo "\nRecipients:\n";
foreach ($result->recipients as $recipient) {
echo " {$recipient['name']} ({$recipient['email']}) - {$recipient['status']}\n";
}
}
echo "\nNext steps:\n";
echo "1. Review the document at the preview URL\n";
echo "2. Send to recipients: TurboSign::send(documentId);\n";
} catch (Exception $error) {
echo "Error: {$error->getMessage()}\n";
}
}
// Run the example
advancedFieldsExample();