Skip to content

Commit 28fd225

Browse files
committed
Select box with scroll to top on payment completion
1 parent c8e6e21 commit 28fd225

4 files changed

Lines changed: 66 additions & 29 deletions

File tree

admin/class-paystack-forms-admin.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ function register_paystack_setting_page() {
4141
register_setting( 'paystack-form-settings-group', 'lsk' );
4242
register_setting( 'paystack-form-settings-group', 'lpk' );
4343
}
44+
function txncheck($name,$txncharge){
45+
if ($name == $txncharge) {
46+
$result = "selected";
47+
}else{
48+
$result = "";
49+
}
50+
return $result;
51+
}
4452
function paystack_setting_page() {
4553
?>
4654
<h1>Paystack Forms API KEYS Settings!</h1>
@@ -49,11 +57,18 @@ function paystack_setting_page() {
4957
<table class="form-table paystack_setting_page">
5058
<tr valign="top">
5159
<th scope="row">Mode</th>
52-
<td><input type="text" name="mode" value="<?php echo esc_attr( get_option('mode') ); ?>" /></td>
60+
61+
<td><select class="form-control" name="mode" id="parent_id">
62+
<option value="live" <?php echo txncheck('live',esc_attr( get_option('mode') )) ?>>Live Mode</option>
63+
<option value="test" <?php echo txncheck('test',esc_attr( get_option('mode') )) ?>>Test Mode</option>
64+
</select>
65+
<!-- <input type="text" name="mode" value="<?php echo esc_attr( get_option('mode') ); ?>" /></td> -->
5366
</tr>
5467
<tr valign="top">
5568
<th scope="row">Test Secret Key</th>
56-
<td><input type="text" name="tsk" value="<?php echo esc_attr( get_option('tsk') ); ?>" /></td>
69+
<td>
70+
71+
<input type="text" name="tsk" value="<?php echo esc_attr( get_option('tsk') ); ?>" /></td>
5772
</tr>
5873

5974
<tr valign="top">
@@ -216,7 +231,8 @@ function my_edit_paystack_form_columns( $columns ) {
216231
$columns = array(
217232
'cb' => '<input type="checkbox" />',
218233
'title' => __( 'Name' ),
219-
'shortcode' => __( 'Shortcode' ),
234+
'shortcode' => __( 'Shortcode' ),
235+
'payments' => __( 'Payments' ),
220236
'date' => __( 'Date' )
221237
);
222238

@@ -225,7 +241,8 @@ function my_edit_paystack_form_columns( $columns ) {
225241
add_action( 'manage_paystack_form_posts_custom_column', 'my_paystack_form_columns', 10, 2 );
226242

227243
function my_paystack_form_columns( $column, $post_id ) {
228-
global $post;
244+
global $post,$wpdb;
245+
$table = $wpdb->prefix . 'paystack_forms_payments';
229246

230247
switch( $column ) {
231248
case 'shortcode' :
@@ -234,6 +251,13 @@ function my_paystack_form_columns( $column, $post_id ) {
234251
readonly="readonly" onfocus="this.select();"></span>';
235252

236253
break;
254+
case 'payments':
255+
256+
$count_query = 'select count(*) from '.$table.' WHERE post_id = "'.$post_id.'" AND paid = "1"';
257+
$num = $wpdb->get_var($count_query);
258+
259+
echo '<a href="'.admin_url('admin.php?page=submissions&form='.$post_id) .'">'. $num.'</a>';
260+
break;
237261
default :
238262
break;
239263
}
@@ -278,7 +302,8 @@ function help_metabox_details( $post ) {
278302

279303
?>
280304
<div class="awesome-meta-admin">
281-
To make an input compulsory add <code> required="required" </code> to the shortcode <br />
305+
To make an input field compulsory add <code> required="required" </code> to the shortcode <br /><br />
306+
It should look like this <code> [text name="Full Name" required="required" ]</code>
282307

283308
</div>
284309

@@ -306,15 +331,7 @@ function wpt_form_data() {
306331
$txncharge = get_post_meta($post->ID, '_txncharge', true);
307332
$loggedin = get_post_meta($post->ID, '_loggedin', true);
308333
$currency = get_post_meta($post->ID, '_currency', true);
309-
function txncheck($name,$txncharge){
310334

311-
if ($name == $txncharge) {
312-
$result = "selected";
313-
}else{
314-
$result = "";
315-
}
316-
return $result;
317-
}
318335
if ($amount == "") {$amount = 0;}
319336
if ($paybtn == "") {$paybtn = 'Pay';}
320337
if ($successmsg == "") {$successmsg = 'Thank you for paying!';}
@@ -490,7 +507,7 @@ public function prepare_items(){
490507

491508
$table = $wpdb->prefix."paystack_forms_payments";
492509
$data = array();
493-
$alldbdata = $wpdb->get_results("SELECT * FROM $table WHERE (post_id = '".$post_id."' AND paid = '0')");
510+
$alldbdata = $wpdb->get_results("SELECT * FROM $table WHERE (post_id = '".$post_id."' AND paid = '1')");
494511

495512
foreach ($alldbdata as $key => $dbdata) {
496513
$newkey = $key+1;
@@ -508,7 +525,7 @@ public function prepare_items(){
508525
$hidden = $this->get_hidden_columns();
509526
$sortable = $this->get_sortable_columns();
510527
usort( $data, array( &$this, 'sort_data' ) );
511-
$perPage = 6;
528+
$perPage = 20;
512529
$currentPage = $this->get_pagenum();
513530
$totalItems = count($data);
514531
$this->set_pagination_args( array(

paystack-forms.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,28 @@ function getSel()
9090
}
9191

9292
QTags.addButton(
93-
"code_shortcode",
93+
"t_shortcode",
9494
"Insert Text",
9595
insertText
9696
);
9797
function insertText(){
9898
QTags.insertContent('[text name="Text Title"]');
9999
}
100100
QTags.addButton(
101-
"code_shortcode",
102-
"Insert Required Text",
103-
insertRText
101+
"ta_shortcode",
102+
"Insert Textarea",
103+
insertTextarea
104104
);
105-
function insertRText(){
106-
QTags.insertContent('[text required="required" name="Text Title"]');
105+
function insertTextarea(){
106+
QTags.insertContent('[textarea name="Text Title"]');
107+
}
108+
QTags.addButton(
109+
"s_shortcode",
110+
"Insert Select Dropdown",
111+
insertSelect
112+
);
113+
function insertSelect(){
114+
QTags.insertContent('[select name="Text Title" options="option 1,option 2,option 2"]');
107115
}
108116
</script>
109117
<?php

public/class-paystack-forms-public.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function cf_shortcode($atts) {
157157
$loggedin = get_post_meta($id,'_loggedin',true);
158158
$txncharge = get_post_meta($id,'_txncharge',true);
159159
$currency = get_post_meta($id,'_currency',true);
160-
print_r($loggedin);
160+
// print_r($loggedin);
161161
if ($loggedin == 'no') {
162162
echo "<h1 id='pf-form".$id."'>".$obj->post_title."</h1>";
163163
echo '<form class="paystack-form" action="' . admin_url('admin-ajax.php') . '" url="' . admin_url() . '" method="post">';
@@ -173,11 +173,11 @@ function cf_shortcode($atts) {
173173
if ($amount == 0) {
174174
echo '<input type="number" name="pf-amount" class="form-control pf-number" id="pf-amount" required/>';
175175
}else{
176-
echo '<input type="number" name="pf-amount" value="'.$amount.'" readonly required/>';
176+
echo '<input type="number" name="pf-amount" value="'.$amount.'" id="pf-amount" readonly required/>';
177177
}
178178
echo '</p>';
179179
echo(do_shortcode($obj->post_content));
180-
echo '<br /><p>Transaction charge:'.$currency.'<b class="txn_charge">13,000</b></p>';
180+
// echo '<br /><p>Transaction charge:'.$currency.'<b class="txn_charge">13,000</b></p>';
181181
// echo '<p>Total charge:'.$currency.'<b class="total_charge">13,000</b></p>';
182182
echo '<p> <br /><input type="submit" value="'.$paybtn.'"></p>';
183183
echo '</form>';
@@ -217,11 +217,19 @@ function select_shortcode($atts) {
217217
'options' => '',
218218
'required' => '0',
219219
), $atts));
220-
$code = '<label> '.$name.'<input class="form-control" type="text" name="'.$name.'"';
220+
$code = '<label> '.$name.'<br /><select class="form-control" name="'.$name.'"';
221+
221222
if ($required == 'required') {
222223
$code.= ' required="reduired" ';
223224
}
224-
$code.= '" /></label><br />';
225+
$code.=" style='width:100%;'>";
226+
$soptions = explode(',', $options);
227+
if (count($soptions) > 0) {
228+
foreach ($soptions as $key => $option) {
229+
$code.= '<option value="'.$option.'" >'.$option.'</option>';
230+
}
231+
}
232+
$code.= '" </select></label><br />';
225233
return $code;
226234
}
227235
add_shortcode('select', 'select_shortcode');

public/js/paystack-forms-public.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
}
4949
$('.paystack-form').on('submit', function(e) {
5050
var stop = false;
51-
$(this).find("input, select, textarea").each(function() {
51+
$(this).find("input, textarea").each(function() {
5252
$(this).css({ "border-color":"#d1d1d1" });
5353
});
5454
var email = $(this).find("#pf-email").val();
@@ -57,6 +57,8 @@
5757
}else{
5858
$(this).find("#pf-amount").css({ "border-color":"red" });
5959
stop = true;
60+
61+
6062
}
6163
if (!validateEmail(email)) {
6264
$(this).find("#pf-email").css({ "border-color":"red" });
@@ -65,7 +67,7 @@
6567
$(this).find("input, select, textarea").filter("[required]").filter(function() { return this.value == ''; }).each(function() {
6668
$(this).css({ "border-color":"red" });
6769
stop = true;
68-
});
70+
});
6971
if (stop) {
7072
return false;
7173
}
@@ -89,11 +91,13 @@
8991
data = JSON.parse(newdata);
9092
if (data.result == 'success'){
9193
$('.paystack-form')[0].reset();
94+
$('html,body').animate({ scrollTop: $('.paystack-form').offset().top - 110 }, 500);
95+
9296
self.before('<pre>'+data.message+'</pre>');
9397
$(this).find("input, select, textarea").each(function() {
9498
$(this).css({ "border-color":"#d1d1d1" });
9599
});
96-
100+
97101
$.unblockUI();
98102
}else{
99103
self.before('<pre>'+data.message+'</pre>');

0 commit comments

Comments
 (0)