Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ช่วยหน่อยครับโค้ดตรวจสอบค่าว่าง และกรอกข้อมูลผิด อย่างจะเปลี่ยนแปลงนิดหน่อย



 

ช่วยหน่อยครับโค้ดตรวจสอบค่าว่าง และกรอกข้อมูลผิด อย่างจะเปลี่ยนแปลงนิดหน่อย

 



Topic : 064688



โพสกระทู้ ( 254 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



ต้อนนี้ผมทำฟร์อมเสร็จแล้วครับแต่ข้อความมันเด้งไปอีกหน้าก่อแล้วกลับมาหน้าเดิมทำให้ข้อมูลหาย แล้วตอนนี้ทำฟร์อมใหม่ขึ้นมาแต่ไม่รุจะให้มันเช็คค่าเหมือนฟร์อมเก่าอย่างไร เหลือแค่ 2 อย่างที่ต้องการให้มันเช็คค่าเหมือฟร์อมเดิมคือ 1. เช็คอีเมล์ จากฐานข้อมูล และ 2. เช็คการกรอกหมายเลขโทรศัพท์

โค้ดฟร์อมเดิมที่เหลือ 1. เช็คอีเมล์ จากฐานข้อมูล และ 2. เช็คการกรอกหมายเลขโทรศัพท์
1. เช็คอีเมล์ จากฐานข้อมูลว่าอีเมล์เคยสมัครหรือไม่
Code (PHP)
$result=select("member","where 1 and Email='".$_POST["txtEmail"]."'");
//============ ถ้าเลือกสมัครสมาชิก
if($_GET["action"]=="Register")
{
	//============ อ่านว่าอีเมล์นี้เคยสมัครหรือยัง
	elseif($result)
	{
		$_POST["txtEmail"]="";
		$_POST["txtEmailCon"]="";
		echo "<script>alert('E-mail นี้เคยสมัครแล้วกรุณาใช่อีเมล์ใหม่')</script>";
		echo"<script>history.back();</script>"; 
		exit();
	}


2. เช็คการกรอกหมายเลขโทรศัพท์

Code (PHP)
if(!ereg("([08]{2})-([0-9]{4})-([0-9]{4})",$_POST['tel']))//หมายเลยต้องเป็นในรูป แบบนี้เท่านั้นไม่สามารถใส่ตัวอักษรได้
	{
		echo "<script>alert('คุณกรอกผิดรูปแบบ 08-XXXX-XXXX')</script>";
		echo"<script>history.back();</script>"; 
		exit();
	}



นี้คือฟร์อมใหม่ ที่ต้องการให้ 2 ข้อนั้นแทรกเข้าไปครับ
Code (PHP)
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="853" height="310" valign="top">
<script language="JavaScript">
function checkvalue()
{
// ============ ตรวจสอบค่าว่าง
if(document.frmRegister.txtEmail.value=="")
{
alert('กรุณากรอก E-mail');
document.frmRegister.txtEmail.focus();
return false;
}
if(document.frmRegister.txtEmailCon.value=="")
{
alert('กรุณา ยืนยัน E-mail ');
document.frmRegister.txtEmailCon.focus();
return false;
}
if(document.frmRegister.txtEmail.value != document.frmRegister.txtEmailCon.value)
{
alert('กรุณา ยืนยันE-mailให้ตรงกัน');
document.frmRegister.txtEmail.focus();
return false;
}
if(document.frmRegister.txtPass.value=="")
{
alert('กรุณากรอก รหัสผ่าน ');
document.frmRegister.txtPass.focus();
return false;
}
if(document.frmRegister.txtPassCon.value=="")
{
alert('กรุณากรอก ยืนยันรหัสผ่าน ');
document.frmRegister.txtPassCon.focus();
return false;
}
if(document.frmRegister.txtPass.value != document.frmRegister.txtPassCon.value)
{
alert('กรุณายืนยันรหัสผ่านให้ตรงกัน');
document.frmRegister.txtPassCon.focus();
return false;
}
if(document.frmRegister.txtName.value=="")
{
alert('กรุณากรอก ชื่อ ');
document.frmRegister.txtName.focus();
return false;
}
if(document.frmRegister.txtLastName.value=="")
{
alert('กรุณากรอก นามสกุล');
document.frmRegister.txtLastName.focus();
return false;
}                              
if(document.frmRegister.txtAddress.value=="")
{
alert('กรุณากรอก ที่อยู่ ');
document.frmRegister.txtAddress.focus();
return false;
}
if(document.frmRegister.txtProvince.value=="")
{
alert('กรุณากรอก จังหวัด ');
document.frmRegister.txtProvince.focus();
return false;
}                              
if(document.frmRegister.txtZipCode.value=="")
{
alert('กรุณากรอก รหัสไปรษณีย์ ');
document.frmRegister.txtZipCode.focus();
return false;
}
if(document.frmRegister.txtTel.value=="")
{
alert('กรุณากรอก หมายเลขโทรศัพท์ ');
document.frmRegister.txtTel.focus();
return false;
}
}
</script>
<form name="frmRegister" method="post" action="?action=Register" onSubmit="return checkvalue()">
<table width="566" border="0" align="center">
<tr>
<td><table width="585" height="22" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
<td bgcolor="#FFCC00"><div align="center" class="style1">แบบฟอร์มสมัครสมาชิก</div></td>
</tr>
</table>
<br></td>
</tr>
<tr>
<td><div align="left">
<p><strong>กรุณากรอกข้อมูลให้ครบตามเครื่องหมาย
(<font color="#FF0000">*</font>) </strong></p>
</div></td>
</tr>
<tr>
<td><p>&nbsp;</p>
<table width="76%" height="484" border="0.5" align="center" cellpadding="2" cellspacing="2" bordercolor="#FF6600" bgcolor="#FFFFFF">
<tr>
<td width="29%">E-mail :</td>
<td width="71%">
<script type='text/javascript'>
function check_email(elm){
var regex_email=/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*\@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.([a-zA-Z]){2,4})$/
if(!elm.value.match(regex_email)){
alert('รูปแบบ E-mail ไม่ถูกต้อง');
}
}
</script>
<input name="txtEmail" type="text" class="txtbox" id="txtEmail" value="<?=$resultUser["Email"];?>" size="30" maxlength="30"onblur='check_email(this)'>
<label></label>
<a href="#" class="menu" onClick="window.open('check.php', 'popup', 'height=150,width=360, left=450,top=150');">Check Username </a><br>                                       
<span class="style3">[email protected]</span></td>
</tr>
<tr>
<td><span class="style2">ยืนยัน E-mail:</span></td>
<td><input name="txtEmailCon" type="text" class="txtbox" id="txtEmailCon" value="<?=$resultUser["Email"];?>" size="30" maxlength="30">
<font color="#FF0000">*</font></td>
</tr>
<tr>
<td>Password :</td>
<td><input name="txtPass" type="password" class="txtbox" id="txtPass" value="<?=$resultUser["Password"];?>" size="30" maxlength="15">
<font color="#FF0000">* <br>
กรอกตัวอักษร,ตัวเลขหรือสัญลักษณ์ใดๆ ไม่เกิน 15 คำ</font></td>
</tr>
<tr>
<td><span class="style2">ยืนยัน Password:</span></td>
<td><input name="txtPassCon" type="password" class="txtbox" id="txtPassCon" value="<?=$resultUser["Password"];?>" size="30" maxlength="15">
<font color="#FF0000">* </font></td>
</tr>
<tr>
<td>ชื่อ - นามสกุล :</td>
<td>
<script language="javascript"> 
function IsNumeric(sText,obj)  
{  
var ValidChars = "ภถ ูุึคตจขชไำฎพฑะธ ัี๊รณนญยฐบลฟฤหฆกฏดโเฌ ้็่๋าษสศวซงผปฉแอฮ ิ์ืทมฒฬใฦฝ";  
var IsNumber=true;  
var Char;  
for (i = 0; i < sText.length && IsNumber == true; i++)   
{   
Char = sText.charAt(i);   
if (ValidChars.indexOf(Char) == -1)   
{ 
IsNumber = false;  
}  
} 
if(IsNumber==false){ 
alert("อักษรไทยเท่านั้น");  
obj.value=sText.substr(0,sText.length-1);  
}  
}  
</script> 
<input name="txtName" type="text" class="txtbox" id="txtName" value="<?=$resultUser["Name"];?>" size="15" maxlength="20"onKeyUp="IsNumeric(this.value,this)">
-
<input name="txtLastName" type="text" class="txtbox" id="txtLastName" value="<?=$resultUser["LastName"];?>" size="15" maxlength="30"onKeyUp="IsNumeric(this.value,this)">
<font color="#FF0000">* <br>
กรอกชื่อจริง นามสกุลจริง ภาษาไทยเท่านั้น</font></td>
</tr>
<tr>
<td>เพศ :</td>
<td><input name="rdoGender" type="radio" value="M" <?if($resultUser["Gender"]=="M"){?>checked<?}?>>
ชาย
<input type="radio" name="rdoGender" value="F" <?if($resultUser["Gender"]=="F"){?>checked<?}?>>
หญิง</td>
</tr>
<tr>
<td valign="top">ที่อยู่ ปัจจุบัน:</td>
<td>
<textarea name="txtAddress" cols="30" rows="2" class="txtbox" id="txtAddress"onKeyUp="IsNumeric(this.value,this)"><?=$resultUser["Address"];?>
</textarea >
<font color="#FF0000">* <br>
กรอกที่อยู่ที่ติดต่อได้จริง ภาษาไทยเท่านั้น</font></td>
</tr>
<tr>
<td>จังหวัด :</td>
<td><input name="txtProvince" type="text" class="txtbox" id="txtTel4" value="<?=$resultUser["Province"];?>" maxlength="20"onKeyUp="IsNumeric(this.value,this)">
<font color="#FF0000">* ภาษาไทยเท่านั้น</font></td>
</tr>
<tr>
<td>รหัสไปรษณีย์ :</td>
<td>
<script language="javascript"> 
function Numeric(sText,obj)  
{  
var ValidChars = "0123456789.";  
var IsNumber=true;  
var Char;  
for (i = 0; i < sText.length && IsNumber == true; i++)   
{   
Char = sText.charAt(i);   
if (ValidChars.indexOf(Char) == -1)   
{  
IsNumber = false;  
}  
}  
if(IsNumber==false){  
alert("ตัวเลขเท่านั้น");  
obj.value=sText.substr(0,sText.length-1);  
}  
}  
</script> 
<input name="txtZipCode" type="text" class="txtbox" id="txtTel3" value="<?=$resultUser["ZipCode"];?>" size="5" maxlength="5"onKeyUp="Numeric(this.value,this)">
<font color="#FF0000">* </font></td>
</tr>
<tr>
<td>หมายเลขโทรศัพท์ :</td>
<td><input name="txtTel" type="text" class="txtbox" id="txtTel" value="<?=$resultUser["Tel"];?>" size="10" maxlength="10"onKeyUp="Numeric(this.value,this)">
<font color="#FF0000">* <br>
กรอกหมายเลขโทรศัพท์ที่ติดต่อได้</font></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<input type="submit" name="Submit" id="Submit" value="ตกลง">
</label>
<label>
<input type="reset" name="Reset" id="button" value="ล้างข้อมูล">
</label></td>
</tr>
</table></td>
</tr>
<tr>
<td width="378">&nbsp;</td>
</tr>
</table>
</form>
<p class="style59">&nbsp;</p>
<p class="style59">&nbsp;</p></td>
</tr>
</table>





Tag : PHP, CakePHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-08-13 22:08:41 By : tormam View : 6422 Reply : 4
 

 

No. 1



โพสกระทู้ ( 254 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ต้องแทรงหรือเปลี่ยนอะไรอย่างไงครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-08-13 22:12:12 By : tormam
 


 

No. 2



โพสกระทู้ ( 254 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ง่า ไม่รุจะต้องแทรงโค้ดไงเลย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-08-13 23:14:17 By : tormam
 

 

No. 3



โพสกระทู้ ( 254 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

......
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-08-14 17:25:16 By : tormam
 


 

No. 4



โพสกระทู้ ( 254 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ได้แล้วครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-08-15 08:45:36 By : tormam
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยหน่อยครับโค้ดตรวจสอบค่าว่าง และกรอกข้อมูลผิด อย่างจะเปลี่ยนแปลงนิดหน่อย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่