|
 |
|
ทำไมตรวจสอบค่าว่าง CKEditor บน Textarea ไม่ได้อ่ะครับมีวิธีแก้ยังไงบ้าง |
|
 |
|
|
 |
 |
|
ผมต้องการเช็คค่าว่างที่จะส่งไปอ่ะครับ
ถ้าTextarea ปกติมันก็เช็คได้ครับแต่พอใช้CKEditoมาด้วยมันเช็คไม่ได้อ่ะครับ
ใครเคยเจอปญหานี้แล้วพอจะมีวิธีแก้บ้างครับ
นี้ครับโค้ด
Code (PHP)
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="ckeditor2/ckeditor.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btbord").click(function(){
//alert('Click Me');
if ($(".ckeditor").val()==""){
alert('กรุณากรอกข้อมูล');
}
});
});
</script>
</head>
<body>
<p>
<?
if ($_POST[btbord]=='ตกลง'){
$title=$_POST[txt_title];
$board=$_POST[txt_board];
$mem_id=$_SESSION[mem_id];
$date = date('Y-m-d H:i:s');
if($_POST[txt_title]==""){
}
$conn="INSERT INTO tbl_board (title,board ,mem_id,datetime)values ('$title','$board','$mem_id','$date')";
$objResult= mysql_db_query($dbname,$conn);
if ($objResult){
echo "ok";
//echo "<meta http-equiv=\"refresh\" content=\"0; URL=index.php?home=weboard\">";
//}else{
//echo"Error";
//exit();
}
}
?>
</p>
<p> </p>
<form id="form1" name="form1" method="post" action="">
<table width="1115" border="1">
<tr>
<td width="164">title bord</td>
<td width="935"><input type="txt_title" name="txt_title" id="txttitle" /></td>
</tr>
<tr>
<td>เนื้อหา</td>
<td><textarea name="txt_board" id="txtboard" cols="45" rows="5" class="ckeditor" ></textarea></td>
</tr>
<tr>
<td>สวัสดีคุณ <? echo "$_SESSION[Name]"; ?></td>
<td><input type="submit" name="btbord" id="btbord" value="ตกลง" /></td>
</tr>
</table>
</form>
</body>
</html>
Tag : PHP, JavaScript, Ajax, jQuery

|
|
 |
 |
 |
 |
Date :
2013-12-31 01:39:59 |
By :
Youcantseeme |
View :
956 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$txt = $_POST['txt_board'];
$need_char_numb = 3;
if(strlen(strip_tags($text)) < $need_char_numb){
echo 'Fail...';
}
|
 |
 |
 |
 |
Date :
2013-12-31 02:39:58 |
By :
t-monroe |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
การตรวจค่าใน CKEditor ต้องผ่าน CKEDITOR.instances ครับ
Code (PHP)
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="ckeditor2/ckeditor.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btbord").click(function(){
//alert('Click Me');
//if ($(".ckeditor").val()==""){
// ต้องตรวจแบบนี้แทน
// โดย CKEDITOR.instances["txtboard"] เป็นการเข้าถึง instance ของ CKEditor ที่ชื่อ txtboard
// และใช้ method getData() ในการอ่านค่าครับ
if (CKEDITOR.instances["txtboard"].getData() == "") {
alert('กรุณากรอกข้อมูล');
}
});
});
</script>
</head>
<body>
<p>
<?
if ($_POST[btbord]=='ตกลง'){
$title=$_POST[txt_title];
$board=$_POST[txt_board];
$mem_id=$_SESSION[mem_id];
$date = date('Y-m-d H:i:s');
if($_POST[txt_title]==""){
}
$conn="INSERT INTO tbl_board (title,board ,mem_id,datetime)values ('$title','$board','$mem_id','$date')";
$objResult= mysql_db_query($dbname,$conn);
if ($objResult){
echo "ok";
//echo "<meta http-equiv=\"refresh\" content=\"0; URL=index.php?home=weboard\">";
//}else{
//echo"Error";
//exit();
}
}
?>
</p>
<p> </p>
<form id="form1" name="form1" method="post" action="">
<table width="1115" border="1">
<tr>
<td width="164">title bord</td>
<td width="935"><input type="txt_title" name="txt_title" id="txttitle" /></td>
</tr>
<tr>
<td>เนื้อหา</td>
<td><textarea name="txt_board" id="txtboard" cols="45" rows="5" class="ckeditor" ></textarea></td>
</tr>
<tr>
<td>สวัสดีคุณ <? echo "$_SESSION[Name]"; ?></td>
<td><input type="submit" name="btbord" id="btbord" value="ตกลง" /></td>
</tr>
</table>
</form>
</body>
</html>
|
ประวัติการแก้ไข 2013-12-31 03:02:38
 |
 |
 |
 |
Date :
2013-12-31 03:02:11 |
By :
phpinfo() |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ ได้แล้วครับ
|
 |
 |
 |
 |
Date :
2014-01-01 19:07:24 |
By :
Youcantseeme |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|