简体   繁体   中英

Validating a form and the integrity of the data using vbscript

Hi I'm interning at a local business and they want me to write a web based application that will take data in and input it into sql. I'm having trouble with calling the vbscript validate function. I know that vbscript is a poor language to use for web dev nowadays but the boss will only use vbscript and visual basic 6 for any programming needs.

<form name="EmployeeForm" action= "ATRAddEditEmployeeForm.asp" method="post">
    Pin Number <input type="text" name="Pin" value=<% = chr(34) & request.querystring("Pin") & chr(34) %>><br/>
    Full Name <input type="text" name="FullName" value=<% = chr(34) & FullName & chr(34) %> /><br/>
    PayRoll ID <input type="text" name="PayRoll" value=<% = chr(34) & PayRoll & chr(34) %>> <br/>
    <input type="radio" name="Status" Value="Active"   <% if Status = "A" then response.write "checked" end if%>/>Active &emsp;
    <input type="radio" name="Status" Value="Terminate"<% if Status = "T" then response.write "checked" end if%>/>Terminate<br/>
    <select>
    'I removed all information inside the select simply because it is not needed        
            </select>
    <input type="submit" name = "cmdSubmit" value ="Submit"/>
</form>
function Validate()
if 1 = 2 then
    Validate = true
else
    Validate = false
end if
msgbox Validate 'the rest of this function is work in progress
response.write "Adc"
' dim SQL
' dim Pin
' dim PayRoll
' dim NumPin
' dim NumPayRoll
' dim FormObject
' dim ErrorReason
' on error resume next
' set FormObject = document.forms("EmployeeForm")
' Pin = FormObject.Pin.Value
' PayRoll = FormObject.PayRoll.Value
' ErrorReason=""
' if connect(1) then
    ' SQL = "SELECT count(Pin) as NumPin from ISO_Employee where pin = " & Pin
    ' if query(rs, sql) then
        ' do until rs.eof
            ' NumPin = dbf(rs,"NumPin")
            ' rs.movenext
        ' loop
        ' rs.close
    ' else
        ' response.write ErrDesc
    ' end if
    ' SQL = "SELECT count(payrollid) as payroll from ISO_Employee where payrollid = " & PayRoll
    ' if query(rs,sql) then
        ' do until rs.eof
            ' NumPayRoll = dbf(rs,"NumPayroll")
            ' rs.movenext
        ' loop
    ' else
        ' response.write ErrDesc
    ' end if
    ' if NumPin <> 0 then
        ' ErrorReason ="Not a unique Pin Number"
    ' end if
    ' if NumPayRoll <> 0 then
        ' ErrorReason = ErrorReason & "Not a unique Pin Number"
    ' end if

    ' disconnect
' else
    ' response.write ErrDesc
' end if
' if ErrorReason <> "" then
    ' 'show why validate failed
    ' Validate = false
' else  
    ' Validate = true
' end if
end function

sub cmdSubmit_onClick 
    If Validate() then
        document.EmployeeForm.submit
    else
        response.write "Failed"
    end if
end sub

It should be noted that the html code is located in a different file than the validate function and the onsubmit function. The validate and onsumbit function are located in a global .asp file that is included in all other pages of this website This should always return a false however it is still posting the form. Does anyone have any idea, or should I do all the validation on the server side and just reload the page if the validation is false?

Well the initial problem is that 1 will never equal 2. You cannot use an integer as a variable.

if **1 = 2** then
    Validate = true
else
    Validate = false
end if

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM