Last active
October 30, 2019 17:46
-
-
Save tradesouthwest/0e41ade121f14dda58e799266ec1a001 to your computer and use it in GitHub Desktop.
Generate a formatted url link from form fields. For WordPress as a shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php /** Shortcode rendering @uses [ipss-generator] 'ipss_payment_generate_payment_link' | |
@package WordPress plugin function */ | |
function ipss_payment_generate_payment_link($atts=array(), $content = null) | |
{ | |
extract(shortcode_atts(array( | |
'ipss_field_nonce' => 'true' | |
), $atts)); | |
$site_base_url = home_url('/'); | |
$ipss_field_first_name = ( empty( $_POST['ipss_field_first_name'] ) ) | |
? '' : sanitize_text_field($_POST['ipss_field_first_name']); | |
$ipss_field_last_name = ( empty( $_POST['ipss_field_last_name'] ) ) | |
? '' : sanitize_text_field($_POST['ipss_field_last_name']); | |
$ipss_field_invoice_number = ( empty( $_POST['ipss_field_invoice_number'] ) ) | |
? '' : sanitize_text_field($_POST['ipss_field_invoice_number']); | |
$ipss_field_amount = ( empty( $_POST['ipss_field_amount'] ) ) | |
? '' : sanitize_text_field($_POST['ipss_field_amount']); | |
$ipss_field_nonce = ( empty( $_POST['ipss_field_nonce'] ) ) | |
? 'true' : sanitize_text_field($_POST['ipss_field_nonce']); | |
ob_start(); | |
echo '<div class="inner ipss-fields"> | |
<form method="post" id="ipssGenerate" action=""> | |
<fieldset class="ipss-input-wrap"> | |
<legend><span class="vmarg">Generate URL Link for Invoice </span></legend> | |
<p><label class="ipsslabel">first name</label> | |
<input type="text" id="ipss_field_first_name" name="ipss_field_first_name" value=""></p> | |
<p><label class="ipsslabel">last name</label> | |
<input type="text" id="ipss_field_last_name" name="ipss_field_last_name" value=""></p> | |
<p><label class="ipsslabel">INVOICE NUMBER</label> | |
<input type="text" id="ipss_field_invoice_number" name="ipss_field_invoice_number" value=""></p> | |
<p><label class="ipsslabel">amount</label> | |
<input type="text" id="ipss_field_amount" name="ipss_field_amount" value=""></p> | |
<p><label class="ipsslabel">validator</label> | |
<input type="text" name="ipss_field_nonce" value="'. $ipss_field_nonce .'"></p> | |
<p><input type="submit" id="ipss-field_submit" class="ipss-submit-button" | |
name="ipss_field_submit" value="Generate"></p> | |
</fieldset> | |
</form> | |
</div> | |
<div id="ipssGenerator">'; | |
if( isset( $_POST['ipss_field_submit'] ) ) : | |
echo esc_url($site_base_url . 'invoice/?ipss_field_first_name=' . $ipss_field_first_name | |
. '&ipss_field_last_name=' . $ipss_field_last_name . '&ipss_field_invoice_number=' . $ipss_field_invoice_number | |
. '&ipss_field_amount=' . $ipss_field_amount . '&ipss_field_nonce=' . $ipss_field_nonce); | |
endif; | |
echo '</div>'; | |
return ob_get_clean(); | |
} | |
/** | |
* Shortcode rendering | |
* Shortcode shows all the information as text on page that is sent via the above query | |
* @uses [ipss-payment] 'ipss_payment_stripe_payment_form' | |
*/ | |
function ipss_payment_stripe_payment_form($atts, $content = null) | |
{ | |
$ipss_field_first_name = ( empty( $_GET['ipss_field_first_name'] ) ) | |
? '' : sanitize_text_field($_GET['ipss_field_first_name']); | |
$ipss_field_last_name = ( empty( $_GET['ipss_field_last_name'] ) ) | |
? '' : sanitize_text_field($_GET['ipss_field_last_name']); | |
$ipss_field_invoice_number = ( empty( $_GET['ipss_field_invoice_number'] ) ) | |
? '' : sanitize_text_field($_GET['ipss_field_invoice_number']); | |
$ipss_field_amount = ( empty( $_GET['ipss_field_amount'] ) ) | |
? '' : sanitize_text_field($_GET['ipss_field_amount']); | |
$ipss_field_nonce = ( empty( $_GET['ipss_field_nonce'] ) ) | |
? '' : sanitize_text_field($_GET['ipss_field_nonce']); | |
if( isset( $_GET['ipss_field_nonce'] ) ) : | |
ob_start(); | |
echo '<div id="ipss-box-container"> | |
<div class="inside ipss-fields ipss-payment-info"> | |
<h4>Payment for: ' . esc_html($ipss_field_first_name) .' ' . esc_html($ipss_field_last_name) .'</h4> | |
<p>Invoice #: ' . esc_html($ipss_field_invoice_number) .'</p> | |
<p>Amount: $' . esc_html($ipss_field_amount) .'</p> | |
</div> | |
</div> | |
<div class ="ipclearfix"></div>'; | |
return ob_get_clean(); | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment