Ajax request using POST method

function update_partial_payment(id)
{
$.ajax({
type: ‘POST’,
url: api_url+’tb_package/update_partial_payment/’,
data: {package_id:id},
success: function() {
location.reload();
}
});
}

 

Advertisements

Dynamic year dropdown with +25 years

<select autocomplete=”cc-exp-year” id=”yer” name=”cd_year” data-validation=”required” data-validation-error-msg=”Credit Card Exp Year”>
<option selected=”selected” value=””>Year</option>
<?php for($i=date(“Y”);$i<date(“Y”)+25;$i++){ ?>
<option value=”<?php echo $i; ?>” <?php echo ($i==$this->input->post(‘cd_year’))?’selected=”selected”‘:”; ?>><?php echo $i; ?></option>
<?php }?>
</select>

Displaying month with for loop

<select autocomplete=”cc-exp-month” id=”mnth” name=”cd_month” data-validation=”required” data-validation-error-msg=” Credit Card Exp Month”>
<option value=””>Month</option>
<?php for($j=1;$j<13;$j++){ ?>
<option value=”<?php if(count(str_split($j)) == 1){ echo ‘0’.$j; }else{ echo $j; } ?>” <?php echo ($j==$this->input->post(‘cd_month’))?’selected=”selected”‘:”; ?>>
<?php if(count(str_split($j)) == 1){ echo ‘0’.$j; }else{ echo $j; } ?>
</option>
<?php } ?>
</select>

class constructor in Codeigniter

This is a normal class constructor. Let’s look at the following example:

class A {
    protected $some_var;

    function __construct() {
        $this->some_var = 'value added in class A';
    }

    function echo_some_var() {
        echo $this->some_var;
    }
}

class B extends A {
    function __construct() {
        $this->some_var = 'value added in class B';
    }
}

$a = new A;
$a->echo_some_var(); // will print out 'value added in class A'
$b = new B;
$b->echo_some_var(); // will print out 'value added in class B'

As you see, class B inherits all values and functions from A. So the class member $some_var is accessible from A as well as from B. Because we’ve added a constructor in class B, the constructor of class A will NOT be used when you are creating a new object of class B.

Now look at the following examples:

class C extends A {
    // empty
}
$c = new C;
$c->echo_some_var(); // will print out 'value added in class A'

As you can see, because we have not declared a constructor, the constructor of class A is used implicitly. But we can also do the following, which is equivalent to class C:

class D extends A {
    function __construct() {
        parent::__construct();
    }
}
$d = new D;
$d->echo_some_var(); // will print out 'value added in class A'

So you only have to use the line parent::__construct(); when you want a constructor in the child class to do something, AND execute the parent constructor. Example given:

class E extends A {
    private $some_other_var;

    function __construct() {
        // first do something important
        $this->some_other_var = 'some other value';

        // then execute the parent constructor anyway
        parent::__construct();
    }
}

Javascript validation for multiple fields

<script type="text/javascript">
		function contact_form()
		{
		var Errmsg = true;		

			if(document.getElementById('email').value=="")
			{
				document.getElementById('err_email').innerHTML = "Email field is required";
				document.getElementById('email').focus();
				Errmsg = false;
			}
			if(document.getElementById('email').value != "")
			{
			var email_id = document.getElementById('email');
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(email_id.value)) {
				document.getElementById('err_email').innerHTML = "Please enter valid email";
				document.getElementById('email').focus();
				Errmsg = false;
			}}
			
			if(document.getElementById('contact').value == "")
			{
				document.getElementById('err_contact').innerHTML = "Contact number field is required";
				document.getElementById('contact').focus();
				Errmsg = false;
			}
			var checkString = document.getElementById("contact").value;
			if (checkString != "") {		
			//var v = document.getElementById("menu_url").value;
			if(!checkString.match(/^[0-9\+\-\(\)]/)) 
			{
				document.getElementById('err_contact').innerHTML = "Please enter valid contact number";
				document.getElementById('contact').focus();
				Errmsg = false;
			}}
			
			if(document.getElementById('name').value=="")
			{
				document.getElementById('err_name').innerHTML = "Name field is required";
				document.getElementById('name').focus();
				Errmsg = false;
			}

/*			if(document.getElementById('captcha_input').value=="")
			{
				document.getElementById('err_captcha_input').innerHTML = "Captcha field is required";
				document.getElementById('captcha_input').focus();
				Errmsg = false;
			}*/
			

			if(Errmsg == false)
			{
				return false;
			}else{
				return true;
			}
		}	
	
	function empty(id)
	{
		if(document.getElementById(id).innerHTML = "")
		return false;
	}
</script>

----------------------------

<form name="contact" method="POST" action="contact-form.php?msg=invalid" onsubmit="return contact_form()">
                    <div class="form_left">Name <span class="red">*</span><span class="form_colon">:</span></div>
                    <div class="form_right">
						<input type="text" value="" class="textbox" name="name" id="name" onkeypress="empty('err_name')" maxlength="50">
						<br><div id="err_name" class="error_js"></div>
					</div>
  
                    <div class="form_left">Contact Number <span class="red">*</span><span class="form_colon">:</span></div>
                    <div class="form_right">
						<input type="text" value="" class="textbox" name="contact" id="contact" onkeypress="empty('err_contact')" maxlength="20">
						<br><div id="err_contact" class="error_js"></div>
					</div>
    
                    <div class="form_left">Email ID <span class="red">*</span><span class="form_colon">:</span></div>
                    <div class="form_right">
						<input type="text" name="email" id="email" value="" class="textbox" onkeypress="empty('err_email')" maxlength="50">
						<br><div id="err_email" class="error_js"></div>
					</div>
    
                    <div class="form_left">Address <span class="form_colon">:</span></div>
                    <div class="form_right">
		<textarea name="address" id="address" cols="" rows="5" class="textarea"></textarea>
					</div>
    
                    <div class="form_left">Message <span class="form_colon">:</span></div>
                    <div class="form_right">
                        <textarea name="description" id="description" cols="" rows="5" class="textarea" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" maxlength="2000">(Maximum 2000 characters allowed)</textarea>
					</div>

<!--
Captcha *:

 

<span style=”min-height:15px; padding-top:8px;font-size:11px;color:#ff0000″>

 

</span> </div>–>


                    <!-- Button begain-->
                    <div class="form_left">&nbsp;</div>
                    <div class="form_right">
                        <div class="checkout_button">
                        <input name="btn_submit" type="submit" value="Submit" class="form_button">
                        </div>
                        <div class="checkout_button">
                        <input name="cancel" type="reset" value="Clear" class="form_button">
                        </div>
                    </div>
				</form>		
                    <!-- Button End-->

 

PHP Version Upgrade – Thread Safe and Non Thread Safe

IIS

If you are using PHP as FastCGI with IIS you should use the Non-Thread Safe (NTS) versions of PHP.

Apache

Please use the Apache builds provided by Apache Lounge. They provide VC9, VC11 and VC14 builds of Apache for x86 and x64. We use their binaries to build the Apache SAPIs.

If you are using PHP as module with Apache builds from apache.org (not recommended) you need to use the older VC6 versions of PHP compiled with the legacy Visual Studio 6 compiler. Do NOT use VC9+ versions of PHP with the apache.org binaries.

With Apache you have to use the Thread Safe (TS) versions of PHP.

TS and NTS

TS refers to multithread capable builds. NTS refers to single thread only builds. Use case for TS binaries involves interaction with a multithreaded SAPI and PHP loaded as a module into a web server. For NTS binaries the widespread use case is interaction with a web server through the FastCGI protocol, utilizing no multithreading (but also for example CLI).