File: /home/kochikidswysewor/public_html/wp-content/themes/children-charity-child/page-sponsor.php
<?php session_start();
/**
* Template Name: Sponsor
*/
get_header();
list($cmsmasters_layout) = children_charity_theme_page_layout_scheme();
$child_id = $_POST['child_id'];
$image = get_the_post_thumbnail($child_id,'child_image_cr');
$categories = get_the_terms( $child_id, 'children_categories' );
$cat_name = $categories[0]->name;
$amount_utilisation = get_field('amount_utilisation',$child_id);?>
<?php if ( is_user_logged_in() ) {
if($child_id){ ?>
<section class="our-sponser">
<div class="container">
<div class="sponsor_donate_wrap">
<h2>Donate</h2>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-4">
<?php if($image){?>
<figure class="kidImg"><?php echo $image; ?></figure>
<?php }else{?>
<figure class="kidImg"><img src="<?php bloginfo("stylesheet_directory"); ?>/img/default.jpg"></figure>
<?php } ?>
</div>
<div class="col-lg-5 col-md-9 col-sm-8">
<table>
<tbody>
<tr>
<td class="hd">Name :</td>
<td class="des"><?php echo get_the_title($child_id);?></td>
</tr>
<tr>
<td class="hd">Age :</td>
<td class="des"><?php echo get_field('age',$child_id);?> years</td>
</tr>
<tr>
<td class="hd">Birthday :</td>
<td class="des"><?php echo get_field('birthday',$child_id); ?></td>
</tr>
<tr>
<td class="hd">Gender :</td>
<td class="des"><?php echo $cat_name; ?></td>
</tr>
</tbody>
</table>
<?php
$paypalID = 'sb-sgpao841819@business.example.com';
//echo $amount_utilisation; ?>
</div>
<div class="col-lg-4 col-md-12 col-sm-12">
<form action="http://www.sandbox.paypal.com/ca/cgi-bin/webscr" method="post" target="_top" name="donation">
<input type="hidden" name="cmd" value="_donations"/>
<input type="hidden" name="amount" id="amount_pass" value="">
<input type="hidden" name="business" value="<?php echo $paypalID; ?>" />
<input type="hidden" name="custom" id="custom_values" value=""><!--Child id-->
<input type="hidden" name="rm" value="2">
<input type="hidden" name="notify_url" value="<?php echo home_url('/thank-you/'); ?>"/>
<input type='hidden' name='return' value='<?php echo home_url('/thank-you/'); ?>'>
<input type="hidden" name="currency_code" value="CAD" />
<div class="input-holder">
<textarea name="sponsor_content" id="sponsor_content" class="txtArea form-control" placeholder="Description" title="Description"></textarea>
</div>
<div class="spnsrAmt" style="display:flex;">
<div class="dnt_amt">
<div class="input-holder">
<input type="number" name="sponsor_amount" id="sponsor_amount" min="0" class="required form-control" placeholder="Amount">
</div>
</div>
<div>
<input type="submit" id="donate_button" class="donate_button btn dnt_more" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" value="Pay" name="Donate" alt="Donate" />
</div>
<!-- <a href="<?php //bloginfo('wpurl');?>/sponsor-dashboard/">Click Here To view all the sponsored Child </a> -->
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<?php }else{ ?>
<p class="sponsor_dtl"></p>
<script>
jQuery('.sponsor_dtl').text('We cannot directly acess this page');
</script>
<?php } ?>
<?php $user = wp_get_current_user();
$user_id = $user->ID;
$user_email = $user->user_email;
$user_name = $user->display_name; ?>
<p class="childid" style="display: none;"><?php echo $child_id; ?></p>
<p class="user_name" style="display: none;"><?php echo $user_name; ?></p>
<p class="user_id" style="display: none;"><?php echo $user_id; ?></p>
<p class="user_email" style="display: none;"><?php echo $user_email; ?></p>
<script>
jQuery('.donate_button').click(function(){
var sponsor_amount = jQuery("#sponsor_amount").val();
jQuery("#amount_pass").val(sponsor_amount); console.log(jQuery("#amount_pass").val());
var sponsor_content = jQuery("#sponsor_content").val();
var childid = jQuery(".childid").text();
var user_name = jQuery(".user_name").text();
var user_id = jQuery(".user_id").text();
var user_email = jQuery(".user_email").text();
var custom_values = sponsor_content+':'+childid+':'+user_name+':'+user_id+':'+user_email;
jQuery("#custom_values").val(custom_values); console.log(jQuery("#custom_values").val());
});
// Validation
jQuery(document).ready(function() {
jQuery('#donate_button').click(function(e){
var amount = jQuery("#sponsor_amount").val(); //alert(amount);
document.cookie="amount="+amount+"";
var $formId = jQuery(this).parents('form');
var formAction = $formId.attr('action');
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var phoneReg = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
var $error = jQuery('<span class="error"></span>');
// Prepare the form for validation - remove previous errors
jQuery('span.error').remove();
jQuery('.input-holder').removeClass('error');
// Validate all inputs with the class "required"
jQuery('.required',$formId).each(function(){
var inputVal = jQuery.trim(jQuery(this).val());
var fieldtitle = jQuery(this).attr("title");
var fieldname=jQuery(this).attr("name");
var $parentTag = jQuery(this).parent(); //alert($parentTag);
if(inputVal == '' || inputVal=='-1')
{
$parentTag.addClass('error').append($error.clone().text('Please enter the amount to donate'));
jQuery(this).focus();
jQuery('#donate_button').show();
return false;
}
});
// All validation complete - Check if any errors exist
// If has errors
if (jQuery('span.error').length > 0) {
jQuery('span.error').each(function(){
// Set the distance for the error animation
var distance = 5;
// Get the error dimensions
var width = jQuery(this).outerWidth();
// Calculate starting position
var start = width + distance;
// Set the initial CSS
jQuery(this).show().css({
display: 'block',
opacity: 1
})
// Animate the error message
.animate({
opacity: 1
}, 'slow');
});
e.preventDefault();
}else{
// var child_id = jQuery(".childid").text();
// var amount = jQuery("#sponsor_amount").val();
// var sponsor_content = jQuery("#sponsor_content").val();
// jQuery.ajax ({
// type: "GET",
// url: "<?php bloginfo('stylesheet_directory');?>/sponsor-data.php",
// dataType: "text",
// data: { amount : amount ,child_id : child_id , sponsor_content : sponsor_content},
// success: function(data) {
// if(data=="yes"){
// alert("successs");
// }
// },
// });
document.donation.submit();
}
// Prevent form submission
e.preventDefault();
});
// Fade out error message when input field gains focus
jQuery('.required').keypress(function(){
var $parent = jQuery(this).parent();
$parent.removeClass('error');
jQuery('span.error',$parent).fadeOut();
});
});
</script>
<?php }else{ ?>
<script>
document.location.href = '<?php echo home_url('/donate-confirmation'); ?>';
</script>
<?php }
get_footer();