PHP form with all type input


for radio type
==============
<input type="radio" value="male" name="gender" class="form-check-input">
<input type="radio" value="female" name="gender" class="form-check-input">

$gender = $_POST['gender'];



for checkbox
=========

  Cricket<input type="checkbox" value="cricket" name="sports[]" class="form-check-input">
  Football<input type="checkbox" value="football" name="sports[]" class="form-check-input">
  Badminton<input type="checkbox" value="badminton" name="sports[]" class="form-check-input">

$sports = $_POST['sports'];
$sports = implode(',', $sports) ;

It's will store the all checked data as separated by comma(,)

for date
=====
<input type="date" name="date" class="form-control my-3">

$date = $_POST['date'];

It's will store the date as year-month-date format (2020-02-20)



<input type="datetime-local" min="2023-07-22T12:00"  max="2017-06-30T16:30" name="date_time_local">

for color
======
<input type="color" name="color">
$color = $_POST['color'];


It's will store the color code as hexa format


If we print a file array

 $file = $_FILES['file'];

print_r($file)
https://prnt.sc/iR-wKQp-B1dh


pathinfo function

print_r(pathinfo('sujon.txt'))
https://prnt.sc/0eyvNJTGJc0x


Print the extension
$sujon =pathinfo('sujon.txt');
echo $sujon['extension'];


Easy method to get extension
echo pathinfo('sujon.txt',PATHINFO_EXTENSION);


File checking in server side
if($myfile['type'] != 'image/png'){
    echo "you need to upload png";
}

Leave a Comment