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'>

&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;!--#include file="../Connections/c_annu_cordonne.asp" --&gt;
&lt;%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL")
If (Request.QueryString &lt;&gt; "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%&gt;
&lt;%
' *** Redirect if username exists
MM_flag="MM_insert"
If (CStr(Request(MM_flag)) &lt;&gt; "" 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,"?" &gt;= 1) Then MM_qsChar = "&"
MM_dupKeyRedirect = MM_dupKeyRedirect & MM_qsChar & "requsername=" & MM_dupKeyUsernameValue
Response.Redirect(MM_dupKeyRedirect)
End If
MM_rsKey.Close
End If
%&gt;
&lt;%
' *** Insert Record: set variables

If (CStr(Request("MM_insert") &lt;&gt; "" 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 &lt;&gt; "" And Request.QueryString &lt;&gt; "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString &lt;&gt; "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%&gt;
&lt;%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert") &lt;&gt; "" 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 &lt;&gt; "" Then
FormVal = AltVal
ElseIf (Delim = "'" Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''" & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i &lt;&gt; 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 &lt;&gt; "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;script language="JavaScript"&gt;
&lt;!--

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()

}
}


//--&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body bgcolor="#FFFFFF" text="#000000"&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;p&gt;&nbsp; &lt;/p&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;form name="form1" method="POST" action="&lt;%=MM_editAction%&gt;"&gt;
&lt;table width="63%" border="1" cellspacing="0" cellpadding="0" height="437" align="center"&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;Choisis&eacute; une rubriques&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;select name="categorie"&gt;
&lt;option value="1" selected&gt;Electronique &lt;/option&gt;
&lt;option value="2"&gt;Electricit&eacute;&lt;/option&gt;
&lt;option value="3"&gt;Immobilier&lt;/option&gt;
&lt;option value="4"&gt;Informatique&lt;/option&gt;
&lt;option value="5"&gt;Mecanique&lt;/option&gt;
&lt;option value="6"&gt;Menuisier&lt;/option&gt;
&lt;option value="7"&gt;Plomberie&lt;/option&gt;
&lt;option value="8"&gt;Autres..............................&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%" height="37"&gt;
&lt;table width="99%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td width="90%"&gt;Nom et Pr&eacute;nom&lt;/td&gt;
&lt;td width="10%"&gt;&lt;font color="#FF3366"&gt;* &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td width="62%" height="37"&gt;
&lt;input type="text" name="Txtnom"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%" height="36"&gt;
&lt;table width="99%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td width="90%"&gt;Profession &lt;/td&gt;
&lt;td width="10%"&gt;&lt;font color="#FF6666"&gt;* &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td width="62%" height="36"&gt;
&lt;input type="text" name="Txtprofession"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;Addresse&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;input type="text" name="Txtaddresse"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%" height="33"&gt;
&lt;table width="99%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td width="90%"&gt;Ville&lt;/td&gt;
&lt;td width="10%"&gt;&lt;font color="#FF3333"&gt;* &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td width="62%" height="33"&gt;
&lt;input type="text" name="Txtville"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;Pays&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;input type="text" name="Txtpays"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;TEL&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;input type="text" name="Txttel"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;G.S.M&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;input type="text" name="Txtgsm"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;E-Mail&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;input type="text" name="Txtemail"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%" height="39"&gt;
&lt;table width="99%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td width="90%"&gt;Site Web&lt;/td&gt;
&lt;td width="10%"&gt;&lt;i&gt;&lt;/i&gt; &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td width="62%" height="39"&gt;
&lt;input type="text" name="Txtsiteweb"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;Commentaires&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;textarea name="Txtcommentaire"&gt;&lt;/textarea&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%" height="99"&gt;&nbsp;&lt;/td&gt;
&lt;td width="62%" height="99"&gt;&lt;i&gt;&lt;b&gt;Remarques :&lt;/b&gt;&lt;/i&gt;Rappelait vous du login
et de mot de mot de passe au cas ou vous voulait modifier ou bien supprimer
votre annonce&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;
&lt;table width="99%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td width="90%"&gt;choisissait un login &lt;/td&gt;
&lt;td width="10%"&gt;&lt;font color="#FF3366"&gt;* &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;input type="text" name="Txtlogin"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;
&lt;table width="99%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td width="90%"&gt;mot de pass &lt;/td&gt;
&lt;td width="10%"&gt;&lt;font color="#FF3366"&gt;* &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;input type="password" name="Txtpass"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="38%"&gt;
&lt;table width="99%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td width="90%"&gt;confirmer le mot de passe &lt;/td&gt;
&lt;td width="10%"&gt;&lt;font color="#FF3366"&gt;* &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td width="62%"&gt;
&lt;input type="password" name="confirmation"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="2" height="74"&gt;
&lt;div align="center"&gt;
&lt;input type="submit" name="submit" value="Envoyer" onClick="Validate()"&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input type="hidden" name="MM_insert" value="true"&gt;
&lt;/form&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;


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

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 :
&lt;input type="submit" name="submit" value="Envoyer" onclick ="return Validate()"&gt;


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>

Reply to this topic