Skip to content

Commit 9a42eeb

Browse files
committed
Added default name field.
1 parent 58cc333 commit 9a42eeb

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function my_editor_content( $content, $post ) {
248248

249249
switch( $post->post_type ) {
250250
case 'paystack_form':
251-
$content = '[text name="Full Name"]';
251+
$content = '[text name="Phone Number"]';
252252
break;
253253
default:
254254
$content = '';
@@ -282,7 +282,7 @@ function help_metabox_details( $post ) {
282282

283283
?>
284284
<div class="awesome-meta-admin">
285-
Email field is added automatically, no need to include that.<br /><br />
285+
Email and Full Name field is added automatically, no need to include that.<br /><br />
286286
To make an input field compulsory add <code> required="required" </code> to the shortcode <br /><br />
287287
It should look like this <code> [text name="Full Name" required="required" ]</code><br /><br />
288288

public/class-paystack-forms-public.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ function cf_shortcode($atts) {
149149
echo '<input type="hidden" name="pf-id" value="' . $id . '" />';
150150
echo '<input type="hidden" name="pf-user_id" value="' . $user_id. '" />';
151151
echo '<p>';
152-
echo 'Email (required)<br />';
152+
echo 'Full Name <br />';
153+
echo '<input type="text" name="pf-fname" class="form-control" required/>';
154+
echo '</p>';
155+
echo 'Email (required)<br />';
153156
echo '<input type="email" name="pf-pemail" class="form-control" id="pf-email" required/>';
154157
echo '</p>';
155158
echo '<p>';
@@ -320,6 +323,7 @@ function paystack_submit_action() {
320323

321324
$table = $wpdb->prefix."paystack_forms_payments";
322325
$metadata = $_POST;
326+
$fullname = $_POST['pf-fname'];
323327
unset($metadata['action']);
324328
unset($metadata['pf-id']);
325329
unset($metadata['pf-pemail']);
@@ -396,7 +400,8 @@ function paystack_submit_action() {
396400
$response = array(
397401
'result' => 'success',
398402
'code' => $insert['txn_code'],
399-
'email' => $insert['email'],
403+
'email' => $insert['email'],
404+
'name' => $fullname,
400405
'total' => $insert['amount']*100,
401406
'custom_fields' => $fixedmetadata
402407
);

public/js/paystack-forms-public.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,16 @@
9292
success: function(data){
9393
$.unblockUI();
9494
if (data.result == 'success'){
95+
var names = data.name.split(' ');
96+
var firstName = names[0] || "";
97+
var lastName = names[1] || "";
98+
// console.log(firstName+ " - "+lastName);
9599
var handler = PaystackPop.setup({
96100
key: settings.key,
97101
email: data.email,
98102
amount: data.total,
103+
firstname: firstName,
104+
lastname: lastName,
99105
ref: data.code,
100106
metadata: {'custom_fields': data.custom_fields},
101107
callback: function(response){

0 commit comments

Comments
 (0)