Jump to content


Photo

Auto Check Textfield Available Or Not!


  • Please log in to reply
4 replies to this topic

#1 whaku

whaku

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 08 December 2012 - 12:08 PM

Hello, im new here.
i see few tutorial here and get stuck in this condition.
i make forum, standart forum using php & few javascript.

here's my register.php
<script type="text/javascript">
function isEmpty(field) {
return trim(field.value).length == 0;
}

function trim(str) {
return str.replace(/^\s*([\S\s]*?)\s*$/, '$1');
}

function validateAForm() {
var form = document.form1;
var username = form.username;
var pass= form.pass;
var email = form.email;
var email2 = form.email2;
if(isEmpty(username)) {
alert("Field UserNama Tidak Boleh Kosong");
username.focus();
return false; //mencegah form disubmit
}
if(isEmpty(pass)) {
alert("Field Password Tidak Boleh Kosong.");
pass.focus();
return false; //mencegah form disubmit
}
if(isEmpty(email)) {
alert("Field E-mail Tidak Boleh Kosong");
email.focus();
return false; //mencegah form disubmit
}
if(email2 != email) {
alert("Field Confirm E-mail tidak sama dengan E-mail.");
email2.focus();
return false; //mencegah form disubmit
}
return true; //teruskan submit
}
</script>
<style type="text/css">
<!--
.style1 { color: #FFFFFF;
font-weight: bold;
}
-->
</style>
<form name="form1" method="post" action="proses_register.php" onsubmit="return validateAForm();">
<table width="83%" border="0" cellpadding="0" cellspacing="2">
<tr>
<td colspan="3"><span class="style1"><font color="#0066CC">REGISTER ID</font></span></td>
</tr>
<tr>
<td width="18%">&nbsp;</td>
<td width="1%">&nbsp;</td>
<td width="81%">&nbsp;</td>
</tr>
<tr>
<td>User Name </td>
<td>&nbsp;</td>
<td><input name="username" type="text" id="username" size="20" maxlength="20" />
<em>ID anda gunakan saat Login </em></td>
</tr>
<tr>
<td>Password</td>
<td>&nbsp;</td>
<td><input name="pass" type="password" id="pass" size="15" maxlength="15" /></td>
</tr>
<tr>
<td>E-mail</td>
<td>&nbsp;</td>
<td><input name="email" type="text" id="email" size="25" /></td>
</tr>
<tr>
<td>Confirm E-mail</td>
<td>&nbsp;</td>
<td><p>
<input name="email2" type="text" id="email2" size="25" />
<br />
</p></td>
</tr>
<tr>
<td>NIM</td>
<td>&nbsp;</td>
<td><input name="nim" type="text" id="nim" size="10" maxlength="10" /></td>
</tr>
<tr>
<td>Tahun Ajaran</td>
<td>&nbsp;</td>
<td><label for="tahunajaran"></label>
<select name="tahunajaran" id="tahunajaran">
<?php
for($a=2000; $a<=2013; $a+=1){
echo"<option value=$a> $a </option>";
}
?>
</select></td>
</tr>
<tr>
<td>Tanggal Lahir</td>
<td>&nbsp;</td>
<td>
<select name="tanggal" id="tanggal">
<?php
for($b=01; $b<=31; $b+=1){
echo"<option value=$b> $b </option>";
}
?>
</select>
<label for="bulan"></label>
<select name="bulan" id="bulan">
<?php
$bulan=array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");
$jlh_bln=count($bulan);
for($c=0; $c<$jlh_bln; $c+=1){
echo"<option value=$bulan[$c]> $bulan[$c] </option>";
}
?>
</select>
<label for="tahun"></label>
<select name="tahun" id="tahun">
<?php
for($d=2000; $d>=1980; $d-=1){
echo"<option value=$d> $d </option>";
}
?>
</select></td>
</tr>
<tr>
<td>Jenis</td>
<td>&nbsp;</td>
<td>
<input type="radio" name="gender" id="gender" value="L" checked="checked" />
Laki-Laki
<input type="radio" name="gender" id="gender" value="P" />
Perempun</td>
</tr>
<tr>
<td colspan="3"><p><font size="-1" color="#0066CC">REGISTER CONFIRMATION!<br>
</font><font size="-1">Untuk mencegah adanya auto register, mohon masukkan code yang terlihat dibawah!</font></p></td>
</tr>
<tr>
<td colspan="3"><p>
<img src="captcha.php" />
<br />
<input name="captcha" type="text" size="10" maxlength="6" />
<br />
</p>
<p>&nbsp;</p></td>
</tr>
<tr>
<td>
<input type="submit" name="Submit" value="Save" />
<input name="Batal" type="reset" id="Batal" value="Batal" /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>

1. I need to make when i put username in that username textfield, automatic search in database its available or not. well its like register on other great forum.
2. i make that captcha, its work but its need progress in proses_register.php, in other words need to open other page to know it granted access to input data or not. i want make it prosess right away after im press submit, maybe like error message in my javascript in 1 row.

thanks before, sorry if my code is mess. im still new programer!

#2 whaku

whaku

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 08 December 2012 - 11:05 PM

sorry i forgot to include this pict for number 1 question.
Posted Image

#3 SocialCloud

SocialCloud

    Advanced Member

  • Members
  • PipPipPip
  • 613 posts

Posted 08 December 2012 - 11:34 PM

1. Query the database

2. What happens when a user has javascript disabled?

Edited by SocialCloud, 08 December 2012 - 11:35 PM.


#4 whaku

whaku

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 09 December 2012 - 12:16 AM

thanks about sugess query.

i never think about that, but if im not wrong i do read people say javascript still work (sorry im not pro about this)
could u give a way with php then?

#5 SocialCloud

SocialCloud

    Advanced Member

  • Members
  • PipPipPip
  • 613 posts

Posted 09 December 2012 - 12:18 AM

If a user has javascript disabled, javascript of course will not work.

$sql = "SELECT `username` FROM table WHERE `username` = '$username'";





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com