-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-auto-usage.php
More file actions
358 lines (311 loc) · 12.2 KB
/
Copy pathexample-auto-usage.php
File metadata and controls
358 lines (311 loc) · 12.2 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
/**
* Example usage of Resume Parser Auto-Detection Feature
*
* This file demonstrates how to use the new auto-detection feature
* that automatically converts any field with the 'resume-parser-field' class
* into a resume parser input field.
*/
// Example 1: Basic WordPress form with auto-parser
function example_job_application_form() {
ob_start();
?>
<div class="job-application-form">
<h3>Job Application Form</h3>
<form method="post" action="">
<?php wp_nonce_field('job_application_submit', 'job_app_nonce'); ?>
<div class="form-group">
<label for="applicant_name">Full Name *</label>
<!-- Adding resume-parser-field class enables auto-parsing -->
<input type="text"
id="applicant_name"
name="applicant_name"
class="resume-parser-field"
required>
</div>
<div class="form-group">
<label for="applicant_email">Email Address *</label>
<input type="email"
id="applicant_email"
name="applicant_email"
class="resume-parser-field"
required>
</div>
<div class="form-group">
<label for="applicant_phone">Phone Number</label>
<input type="tel"
id="applicant_phone"
name="applicant_phone"
class="resume-parser-field">
</div>
<div class="form-group">
<label for="position_applied">Position Applied For</label>
<input type="text"
id="position_applied"
name="position_applied">
</div>
<div class="form-group">
<label for="work_experience">Work Experience</label>
<textarea id="work_experience"
name="work_experience"
class="resume-parser-field"
rows="5"></textarea>
</div>
<div class="form-group">
<label for="education">Education Background</label>
<textarea id="education"
name="education"
class="resume-parser-field"
rows="3"></textarea>
</div>
<div class="form-group">
<label for="skills">Technical Skills</label>
<textarea id="skills"
name="skills"
class="resume-parser-field"
rows="3"></textarea>
</div>
<div class="form-group">
<label for="cover_letter">Cover Letter</label>
<textarea id="cover_letter"
name="cover_letter"
rows="5"></textarea>
</div>
<button type="submit" name="submit_application" class="btn btn-primary">
Submit Application
</button>
</form>
</div>
<style>
.job-application-form {
max-width: 600px;
margin: 20px auto;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #333;
}
.form-group input,
.form-group textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
box-sizing: border-box;
}
.form-group textarea {
resize: vertical;
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
text-decoration: none;
display: inline-block;
}
.btn-primary {
background: #007cba;
color: white;
}
.btn-primary:hover {
background: #005a87;
}
</style>
<?php
return ob_get_clean();
}
// Example 2: Handle form submission and process resume data
function handle_job_application_submission() {
if (isset($_POST['submit_application']) && wp_verify_nonce($_POST['job_app_nonce'], 'job_application_submit')) {
// Get regular form fields
$applicant_data = array(
'name' => sanitize_text_field($_POST['applicant_name']),
'email' => sanitize_email($_POST['applicant_email']),
'phone' => sanitize_text_field($_POST['applicant_phone']),
'position' => sanitize_text_field($_POST['position_applied']),
'work_experience' => sanitize_textarea_field($_POST['work_experience']),
'education' => sanitize_textarea_field($_POST['education']),
'skills' => sanitize_textarea_field($_POST['skills']),
'cover_letter' => sanitize_textarea_field($_POST['cover_letter'])
);
// Get parsed resume data (if any resume was uploaded)
$resume_data = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'resume_') === 0 && $key !== 'resume_parser_used' && $key !== 'resume_parser_target') {
$clean_key = str_replace('resume_', '', $key);
$resume_data[$clean_key] = sanitize_textarea_field($value);
}
}
// Check if resume parser was used
$resume_parser_used = false;
foreach ($_POST as $key => $value) {
if (strpos($key, 'resume_parser_used_') === 0) {
$resume_parser_used = true;
break;
}
}
// Save application data
$application_id = wp_insert_post(array(
'post_type' => 'job_application',
'post_title' => 'Application from ' . $applicant_data['name'],
'post_content' => $applicant_data['cover_letter'],
'post_status' => 'private',
'meta_input' => array(
'_applicant_data' => $applicant_data,
'_resume_data' => $resume_data,
'_resume_parser_used' => $resume_parser_used,
'_application_date' => current_time('mysql')
)
));
if ($application_id) {
echo '<div class="notice notice-success"><p>Application submitted successfully! ID: ' . $application_id . '</p></div>';
// Debug: Show what data was captured
if ($resume_parser_used) {
echo '<div class="notice notice-info"><p><strong>Resume Parser Data Captured:</strong></p>';
echo '<pre>' . print_r($resume_data, true) . '</pre></div>';
}
} else {
echo '<div class="notice notice-error"><p>Error submitting application. Please try again.</p></div>';
}
}
}
// Example 3: Shortcode for the job application form
function job_application_form_shortcode($atts) {
// Handle form submission
handle_job_application_submission();
// Return the form
return example_job_application_form();
}
add_shortcode('job_application_form', 'job_application_form_shortcode');
// Example 4: Contact form with resume parser
function example_contact_form_with_resume() {
ob_start();
?>
<div class="contact-form-with-resume">
<h3>Contact Us</h3>
<p>Fill out this form to get in touch. You can upload your resume to auto-fill your information.</p>
<form method="post" action="">
<div class="form-row">
<div class="form-group">
<label for="contact_name">Your Name</label>
<input type="text"
id="contact_name"
name="contact_name"
class="resume-parser-field">
</div>
<div class="form-group">
<label for="contact_email">Email</label>
<input type="email"
id="contact_email"
name="contact_email"
class="resume-parser-field">
</div>
</div>
<div class="form-group">
<label for="subject">Subject</label>
<input type="text"
id="subject"
name="subject">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea id="message"
name="message"
rows="5"></textarea>
</div>
<button type="submit" name="submit_contact" class="btn btn-primary">
Send Message
</button>
</form>
</div>
<?php
return ob_get_clean();
}
// Example usage in WordPress
/*
// To use these examples, add them to your theme's functions.php or create a custom plugin
// 1. Add the shortcode to any page/post:
[job_application_form]
// 2. Or call directly in template:
echo example_job_application_form();
// 3. Handle the auto-detection:
// The resume-parser-field class will automatically be detected by the JavaScript
// and resume parser interfaces will be added dynamically.
// 4. Form submission data will include:
// - Regular form fields (applicant_name, applicant_email, etc.)
// - Parsed resume fields (resume_name, resume_email, resume_phone, etc.)
// - Tracking fields (resume_parser_used_fieldname, resume_parser_target_fieldname)
*/
// Example 5: Admin interface to view applications with resume data
function view_applications_with_resume_data() {
if (!current_user_can('manage_options')) {
return;
}
$applications = get_posts(array(
'post_type' => 'job_application',
'posts_per_page' => -1,
'post_status' => 'private'
));
echo '<div class="wrap">';
echo '<h1>Job Applications</h1>';
foreach ($applications as $app) {
$applicant_data = get_post_meta($app->ID, '_applicant_data', true);
$resume_data = get_post_meta($app->ID, '_resume_data', true);
$resume_used = get_post_meta($app->ID, '_resume_parser_used', true);
echo '<div style="background: #fff; padding: 20px; margin: 10px 0; border: 1px solid #ddd;">';
echo '<h3>' . esc_html($app->post_title) . '</h3>';
echo '<p><strong>Date:</strong> ' . get_the_date('Y-m-d H:i:s', $app->ID) . '</p>';
if ($resume_used) {
echo '<p><strong>Resume Parser Used:</strong> Yes</p>';
echo '<h4>Parsed Resume Data:</h4>';
echo '<ul>';
foreach ($resume_data as $key => $value) {
if (!empty($value)) {
echo '<li><strong>' . ucfirst($key) . ':</strong> ' . esc_html($value) . '</li>';
}
}
echo '</ul>';
}
echo '<h4>Form Data:</h4>';
echo '<ul>';
foreach ($applicant_data as $key => $value) {
if (!empty($value)) {
echo '<li><strong>' . ucfirst(str_replace('_', ' ', $key)) . ':</strong> ' . esc_html($value) . '</li>';
}
}
echo '</ul>';
echo '</div>';
}
echo '</div>';
}
// Register custom post type for job applications
function register_job_application_post_type() {
register_post_type('job_application', array(
'labels' => array(
'name' => 'Job Applications',
'singular_name' => 'Job Application'
),
'public' => false,
'show_ui' => true,
'show_in_menu' => 'users.php',
'capability_type' => 'post',
'capabilities' => array(
'create_posts' => 'manage_options',
),
'map_meta_cap' => true,
));
}
add_action('init', 'register_job_application_post_type');
?>