user3142334
user3142334

Reputation: 53

Validating credit card details in Codeigniter

I am new to codeigniter. Below is my form where user enters credit card details.

How to validate this information in the controller. I've searched a lot but didn't get any exact information regarding it.

<!DOCTYPE html> 
<html>
    <head>
        <title>Payment</title>
        <link rel="stylesheet" href="http://localhost/cinema/assets/css/form1.css">
    </head>

 <body>

<div id="contact">
<form action="http://localhost/cinema/Movies/save" method="post" accept-charset="utf-8"> 
<h3>Enter Credit Card details:</h3>

Cardholder's Name: <input type="text" name="ccName"><br>      

CreditCard Number: <input type="text" name="ccNum"><br>      

CreditCard type: <div class="drop"><select name="ccType">      

<option value="Mastercard">Mastercard</option>      

<option value="Visa">Visa</option>      

<option value="Amex">Amex</option>      

<option value="Discover">Discover</option>      

</select></div><br>      

Expiry Date: <div class="date"><select name="ccExpM">       

<?php      

 for ($i = 1; $i < 13; $i++) {
     echo '<option>' . $i . '</option>';
 }      

 ?>       

 </select>   

 <select name="ccExpY">      

 <?php      

 for ($i = 2004; $i < 2016; $i++) {
     echo '<option>' . $i . '</option>';
 }      

 ?>       

</select></div><br><br>      

<input type="submit" name="submit" value="Submit">      

</form>  
</div>
</body>
</html>

Upvotes: 1

Views: 1755

Answers (1)

Dan Blows
Dan Blows

Reputation: 21174

In CodeIgniter, you can add custom validators. Symfony2 offers a bunch of validators (including credit card details) and you can just use those classes in CI.

For example, the 'card scheme' validator - documentation and code.

Upvotes: 2

Related Questions