Forums
This topic is locked
how stop inserting record with form if it's error?
Posted 04 Sep 2001 00:18:15
1
has voted
04 Sep 2001 00:18:15 anouar stevens posted:
i have a page with insert record with a form and i have a ajavascript to verify if the login is writed and virify the confirmation of the password , so when i click to valide the form without typing login i have a error from javascipt but when i click ok the form continue the insert the information , it's not normale right? so how i can to stop insert the informaztion to the database if i have an error from my document any help will be apprecie
this is the code of my document :
****************************<font face='Comic Sans MS'></font id='Comic Sans MS'>
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/c_annu_cordonne.asp" -->
<%
' *** Edit Operations: declare variables
MM_editAction = CStr(Request("URL")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Redirect if username exists
MM_flag="MM_insert"
If (CStr(Request(MM_flag)) <> "" Then
MM_dupKeyRedirect="annuaire_simple1.shtml"
MM_rsKeyConnection=MM_c_annu_cordonne_STRING
MM_dupKeyUsernameValue = CStr(Request.Form("Txtlogin")
MM_dupKeySQL="SELECT loginn FROM cordonne WHERE loginn='" & MM_dupKeyUsernameValue & "'"
MM_adodbRecordset="ADODB.Recordset"
set MM_rsKey=Server.CreateObject(MM_adodbRecordset)
MM_rsKey.ActiveConnection=MM_rsKeyConnection
MM_rsKey.Source=MM_dupKeySQL
MM_rsKey.CursorType=0
MM_rsKey.CursorLocation=2
MM_rsKey.LockType=3
MM_rsKey.Open
If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
' the username was found - can not add the requested username
MM_qsChar = "?"
If (InStr(1,MM_dupKeyRedirect,"?" >= 1) Then MM_qsChar = "&"
MM_dupKeyRedirect = MM_dupKeyRedirect & MM_qsChar & "requsername=" & MM_dupKeyUsernameValue
Response.Redirect(MM_dupKeyRedirect)
End If
MM_rsKey.Close
End If
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert") <> "" Then
MM_editConnection = MM_c_annu_cordonne_STRING
MM_editTable = "cordonne"
MM_editRedirectUrl = "recu.shtml"
MM_fieldsStr = "categorie|value|Txtnom|value|Txtprofession|value|Txtaddresse|value|Txtville|value|Txtpays|value|Txttel|value|Txtgsm|value|Txtemail|value|Txtsiteweb|value|Txtcommentaire|value|Txtlogin|value|Txtpass|value"
MM_columnsStr = "categorie|none,none,NULL|name|',none,''|profession|',none,''|addresse|',none,''|ville|',none,''|pays|',none,''|tel|',none,''|gsm|',none,''|email|',none,''|web|',none,''|commentaires|',none,''|loginn|',none,''|passwordd|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"
' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
If (CStr(Request("MM_insert") <> "" Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),","
Delim = MM_typeArray(0)
If (Delim = "none" Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none" Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none" Then EmptyVal = ""
If (FormVal = "" Then
FormVal = EmptyVal
Else
If (AltVal <> "" Then
FormVal = AltVal
ElseIf (Delim = "'" Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''" & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & " values (" & MM_dbValues & ""
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function Validate() {
if(form1.Txtlogin.value == "" {
alert("You must enter your Login."
form1.Txtlogin.focus();
} else if (form1.Txtpassword.value == "" {
alert("You must enter your password."
form1.Txtpassword.focus();
} else if (form1.Txtconfirmation.value == "" {
alert("You must re-enter your password for confirmation."
form1.Txtconfirmation.focus();
} else if(form1.Txtpassword.value != form1.confirmation.value) {
alert("Passwords entered do not match."
form1.Txtpassword.value = "";
form1.confirmation.value = "";
form1.Txtpassword.focus();
} else {
form1.submit()
}
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<p> </p>
<p> </p>
<form name="form1" method="POST" action="<%=MM_editAction%>">
<table width="63%" border="1" cellspacing="0" cellpadding="0" height="437" align="center">
<tr>
<td width="38%">Choisisé une rubriques</td>
<td width="62%">
<select name="categorie">
<option value="1" selected>Electronique </option>
<option value="2">Electricité</option>
<option value="3">Immobilier</option>
<option value="4">Informatique</option>
<option value="5">Mecanique</option>
<option value="6">Menuisier</option>
<option value="7">Plomberie</option>
<option value="8">Autres..............................</option>
</select>
</td>
</tr>
<tr>
<td width="38%" height="37">
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="90%">Nom et Prénom</td>
<td width="10%"><font color="#FF3366">* </font></td>
</tr>
</table>
</td>
<td width="62%" height="37">
<input type="text" name="Txtnom">
</td>
</tr>
<tr>
<td width="38%" height="36">
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="90%">Profession </td>
<td width="10%"><font color="#FF6666">* </font></td>
</tr>
</table>
</td>
<td width="62%" height="36">
<input type="text" name="Txtprofession">
</td>
</tr>
<tr>
<td width="38%">Addresse</td>
<td width="62%">
<input type="text" name="Txtaddresse">
</td>
</tr>
<tr>
<td width="38%" height="33">
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="90%">Ville</td>
<td width="10%"><font color="#FF3333">* </font></td>
</tr>
</table>
</td>
<td width="62%" height="33">
<input type="text" name="Txtville">
</td>
</tr>
<tr>
<td width="38%">Pays</td>
<td width="62%">
<input type="text" name="Txtpays">
</td>
</tr>
<tr>
<td width="38%">TEL</td>
<td width="62%">
<input type="text" name="Txttel">
</td>
</tr>
<tr>
<td width="38%">G.S.M</td>
<td width="62%">
<input type="text" name="Txtgsm">
</td>
</tr>
<tr>
<td width="38%">E-Mail</td>
<td width="62%">
<input type="text" name="Txtemail">
</td>
</tr>
<tr>
<td width="38%" height="39">
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="90%">Site Web</td>
<td width="10%"><i></i> </td>
</tr>
</table>
</td>
<td width="62%" height="39">
<input type="text" name="Txtsiteweb">
</td>
</tr>
<tr>
<td width="38%">Commentaires</td>
<td width="62%">
<textarea name="Txtcommentaire"></textarea>
</td>
</tr>
<tr>
<td width="38%" height="99"> </td>
<td width="62%" height="99"><i><b>Remarques :</b></i>Rappelait vous du login
et de mot de mot de passe au cas ou vous voulait modifier ou bien supprimer
votre annonce</td>
</tr>
<tr>
<td width="38%">
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="90%">choisissait un login </td>
<td width="10%"><font color="#FF3366">* </font></td>
</tr>
</table>
</td>
<td width="62%">
<input type="text" name="Txtlogin">
</td>
</tr>
<tr>
<td width="38%">
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="90%">mot de pass </td>
<td width="10%"><font color="#FF3366">* </font></td>
</tr>
</table>
</td>
<td width="62%">
<input type="password" name="Txtpass">
</td>
</tr>
<tr>
<td width="38%">
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="90%">confirmer le mot de passe </td>
<td width="10%"><font color="#FF3366">* </font></td>
</tr>
</table>
</td>
<td width="62%">
<input type="password" name="confirmation">
</td>
</tr>
<tr>
<td colspan="2" height="74">
<div align="center">
<input type="submit" name="submit" value="Envoyer" onClick="Validate()">
</div>
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="true">
</form>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
Replies
Replied 04 Sep 2001 14:16:05
04 Sep 2001 14:16:05 Andrew Watson replied:
Use the form validation extension available at udzone!!! (i think thats what you need, anyway)
<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Leed
<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Leed
Replied 05 Sep 2001 18:38:10
05 Sep 2001 18:38:10 anouar stevens replied:
THINK4S FOR YOU HELP BUT I JUST FIND A GOOD IDEA TO STOP IT I JUST ADD "RETURN" TO MY CODE OF PAGE LIKE THIS :
<input type="submit" name="submit" value="Envoyer" onclick ="return Validate()">
and in the code of my script if i have error i put : return false and if i don't have error i put return true ,
and it's work very good <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
<input type="submit" name="submit" value="Envoyer" onclick ="return Validate()">
and in the code of my script if i have error i put : return false and if i don't have error i put return true ,
and it's work very good <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Replied 06 Sep 2001 02:23:10
06 Sep 2001 02:23:10 Waldo Smeets replied:
Perfect solution!
Waldo Smeets - www.UDzone.com Webmaster
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Waldo Smeets - www.UDzone.com Webmaster
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>