-3

Why is the below code not working and no response is received? Please help!

I want to check the Name.

 <?php
  echo '<form name="form">';
  echo '<input type="text" name="Name" >';
  echo '<input type="button" class="save" value="save" onClick="Check()" />';
  echo '</form>';

$_POST["Name"] = $Name;

echo '<SCRIPT type="text/javascript">';
echo 'function Check(){';
echo 'if( strlen($Name) < 8) {';
echo 'alert("error name");';
echo '}else {';
echo 'form.submit();';
echo '}';
echo '}';
echo '</SCRIPT>';
?>
SaschaM78
  • 4,376
  • 4
  • 33
  • 42
buy buy
  • 1
  • 3

1 Answers1

1

If you want to do it with pure php

<form name="form" action="" method="post">
    <input type="text" name="name" >
    <input type="submit" value="save" />
</form>

<?php

if(isset($_POST['submit'])){
    if(isset($_POST['name']) && strlen($_POST['name']) < 8) {
        echo  htmlentities($_POST['name']);
        exit;
    }else {
        //FORM SUBMITION CODE
    }
}
?>

For More Look At PHP Form Handling

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
TarangP
  • 2,711
  • 5
  • 20
  • 41