?
Solved

how do i do server side validations with dreamwaever. have code but its buggy

Posted on 2004-04-05
5
Medium Priority
?
198 Views
Last Modified: 2010-04-25
Hello,
I have just tried to do server side validations with dreamweaver, The code i added into the page works when you first go to page, If a user submits wrong information, or goes to the page, leaves and then comes back, the error will stay until they submit properly...

this is my code

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="head.asp" -->
<!--#include file="topbanner.asp" -->
<!--#include file="../Connections/mine.asp" -->

<%                          
                         
 if  Session("Errors")=0 then
  response.write ""
else
  'ERRORS WERE MADE SO LIST THEM IN THE REST OF THE TABLE
  'reset our error counter
  Session("Errors")="0"

  'THESE SESSION VARIABLES ARE SET IN THE SECOND PAGE
  ' IF THERE WERE ERRORS 'VALUE IS "F"  
  If Session("badFirstName") = "T" then
     Response.write "<font color='red'>The State Name field must be completed.</font>"
     Session("badFirstName")="F"
  End If

End If
%>      
            


<%
Session("FName")=Request("FirstName")


'HERE IS ONE WAY OF CHECKING FOR AN EMPTY TEXT BOX
if not len(Request("stateName")) > 0 then
  Session("badFirstName")="T"
  Session("Errors")=Session("Errors") + 1
end if



if Session("Errors") > 0 then

response.write ""

else


Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
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 = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

  MM_editConnection = MM_mine_STRING
  MM_editTable = "dbo.t_state"
  MM_editRedirectUrl = "stateList.asp"
  MM_fieldsStr  = "stateName|value|stateCountry|value"
  MM_columnsStr = "stateName|',none,''|stateCountry|none,1,0"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
 
  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_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

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then  ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_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
%>

<%
end if
%>

             
                         
                  <form method="post" action="<%=MM_editAction%>" name="form1">
                    <table width="328" height="92" align="left">
                      <tr align="left" valign="top">
                        <td width="72" nowrap class="bodyAdmin">Name:</td>
                        <td width="244"> <input type="text" name="stateName" value="<%=Session("SName")%>" size="32">
                        </td>
                      </tr>
                      <tr align="left" valign="top">
                        <td nowrap>&nbsp;</td>
                        <td> <input type="checkbox" name="stateCountry" value=1 > 
                          <span class="bodyAdmin"> If not in the U.S.A. please
                          check</span></td>
                      </tr>
                      <tr align="left" valign="top">
                        <td nowrap>&nbsp;</td>
                        <td> <input type="submit" value="Insert Record"> </td>
                      </tr>
                    </table>
                    <input type="hidden" name="MM_insert" value="form1">
                  </form>
                  <p>&nbsp;</p></td>
              </tr>
            </table>
           
          </TD>  
          <TD background="images/DropShadow.gif">&nbsp; </TD>
      </TR>
</TABLE>      
      
<!--#include file="footer.asp" -->

</td></tr></table>
</BODY>
</HTML>
0
Comment
Question by:jblayney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:pheine
ID: 10769940
Hi jblayney,

i dont get your problem with the code.

"If a user submits wrong information,"
thats the point of validating someone...

"or goes to the page, leaves and then comes back"
thats cause you are using session() - if you want to store his validation longer than 20min or as long as he is on your side you have to use request/response.cookies()

", the error will stay until they submit properly..."
cause he is not validated...

can't say more to this...
0
 
LVL 1

Author Comment

by:jblayney
ID: 10771570
Ok
its hard to explain.....

If the user submits the wrong information in the form, the validation comes up,,,which is good....IF they then decdie not to fix the error, leave the page and come back later, the error message will be waiting for them when they get back.....

Also....

They can go to the form page,,,not do anything at all, (dont fill form, dont hit submit), leave the page and come back in 2 minutes, the error is then there, even though they didnt submit...
0
 
LVL 2

Accepted Solution

by:
pheine earned 200 total points
ID: 10772963
well...

it's not really a problem. can't write the code now cause i'm at work but a small manual how to fix this:

form:
insert an hidden input field named 'formsend' or anything like this with value '1'

at the top of the page check if request.form("formsend") = "1". in this if clause check the other values and store them. if the values are wrong show the error.

after that comes the other code...


the thing is, that you have to check the values of the form only when the form was submitted.
0
 
LVL 1

Author Comment

by:jblayney
ID: 10774458
Tx Phiene,

such a simple answer and it worked so well, I have had this posted for a week and 2 different ways and this is my first response....

I have 1 more question I am going to post, It is title "differnt validations for form"

maybe you can help me again, I jsut want to be able to check for numbers, charaters and email....
0
 
LVL 1

Author Comment

by:jblayney
ID: 10774467
ill post it in asp too
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question