1

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>
Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
user3142334
  • 53
  • 1
  • 11
  • Did you have any chance to take a look at CI doc? It [is well explained](http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#validationrules) how to validate forms by using validation class. – Hashem Qolami Jan 16 '14 at 12:45
  • Are you asking about how to do the vaildation of the creditcard or how to do validation in CodeIgniter? – David Mulder Jan 16 '14 at 12:51
  • possible duplicate of [What is the best way to validate a credit card in PHP?](http://stackoverflow.com/questions/174730/what-is-the-best-way-to-validate-a-credit-card-in-php) – David Mulder Jan 16 '14 at 12:51
  • Or otherwise just the link of Hashem Qolami – David Mulder Jan 16 '14 at 12:52

1 Answers1

2

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.

Dan Blows
  • 20,846
  • 10
  • 65
  • 96