提示验证并在取消时返回false

i'm developing a PHP web application.
On Categories page which shows all categories i would like to put an edit submit button which on click event will open a prompt button with the category name to change it if the user wants.

I would also like to have some validations on prompt box (min-length='5') and if the user clicks on cancel button to return false(returns null now) and not submit the form else if validation is ok and clicks ok to submit the form with the category id and the new category name (prompt value) to update the data.

Sample of code:

echo "<table>";
$strCats=$con->query("SELECT * FROM categories ORDER BY catName");
$CatsRows=$strCats->rowCount();
if ($CatsRows==0) {
  echo "NO DATA FOUND";
}else{
  while($CatsRow = $strCats->fetch()){
    echo "<tr><td>$CatsRow[catName]</td>
    <td><button type='submit' name='btnEditCategory' value='$CatsRow[catId]' onclick='return prompt(\"Rename category\",\"$CatsRow[catName]\");'>EDIT</button></td></tr>";
  }
}
echo "</table>";

You will need to use a javascript function which runs on button click and submit the value via ajax.

<script type="text/javascript">
     function btnEditCategory(catID){
        //edit function with ajax call to edit category
     }
</script>
<input type="submit" onclick="return btnEditCategory('1');" value="Edit">

Pass the category ID to edit in the edit function

Finally i solve it.

if(isset("cmdEditCategory")){
  $catName = str_replace('"',"`",str_replace("'","`",$_POST['txtCatName']));
  $catId = $_POST['cmdEditCategory'];
  $sqlEditCategory=$con->prepare("UPDATE categories SET catName=? WHERE catId=?");
  $sqlEditCategory->bindParam(1, $catName, PDO::PARAM_STR, 25);
  $sqlEditCategory->bindParam(2, $catId, PDO::PARAM_INT, 11);
  if ($sqlEditCategory->execute()) {
    echo "<script type='text/javascript'>notif('success','". MSG_SUCCESS ."','". MSG_UPDATED ."');</script>";
  }else{
    echo "<script type='text/javascript'>notif('error','". MSG_WARNING ."','". MSG_ERROR ."');</script>";
  }
}
$strCats=$con->query("SELECT * FROM categories ORDER BY catName");
$CatsRows=$strCats->rowCount();
if ($CatsRows==0) {
  echo "<div class='alert alert-danger'>". MSG_NO_DATA_FOUND ."</div>";
}else{
  echo "<form action='/..$_SERVER[REQUEST_URI]' method='post'>
    <table>";
    while($CatsRow = $strCats->fetch()){
      echo "<tr><td>$CatsRow[catName]</td>
        <td>
          <button type='submit' name='cmdEditCategory' value='$CatsRow[catId]' onclick='return editCategory(\"$CatsRow[catName]\");'>". EDIT ."</button>
        </td>
      </tr>";
    }
    echo "</table>
    <div style='display:none'>
      <input type='text' id='txtCatName' name='txtCatName' />
    </div>
  </form>
  <script type='text/javascript'>
    function editCategory(catName){
      var msg = prompt('Rename category',catName);
      if(msg != null){
        document.getElementById('txtCatName').value=msg;
        return true;
      }else{
        return false;
      }
    }
  </script>";
}

If there is another better solution please reply.