Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2003
    Location
    N. Ireland
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    stop a form being posted

    hi again guys, thanks for the last help, i have taken note of the login weaknesses pointed out by whammy and glenngv and changed that code, though i did say i wanted to learn how to do those things for other purposes and that has now been successfully completed...i have also tidied up my code, removing dozens of superflous lines and unneccessary variables littered around the place...now my problem is with this function to ensure certain required fields are entered to text boxes on an add new form
    code:
    ----------------------------------------------------------------
    <Script LANGUAGE="VBSCRIPT">

    Function CkISfilled()
    strvenue = Document.Form.Tvenue.Value
    strevent = Document.Form.Tevent.Value

    IF Document.Form.Tvenue.Value="" OR Document.Form.Tevent.Value="" THEN
    msgBox "You must enter required Fields"
    END IF
    END FUNCTION

    </SCRIPT>
    ----------------------------------------------------------------------
    code:

    this function runs then the form is posted so what i what to do is stop the form being posted and after this function, can this be done?.
    ska

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    676
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ska...
    /me doesnt just a do® this kinda stuff...
    'cept ummm...did ya try telling it to just a lert® vs the msgBox ???

    just a guessin'® n' keeping ya company til the pros come just a long® lol...

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If this function is returning the validation then you need to return a boolean of whether the form is valid or not.

    Code:
    Function CkISfilled(strvenue,strevent) 
    IF strvenue="" OR strevent="" THEN 
    CkISfilled = false
    msgBox "You must enter required Fields" 
    Else
    CkISfilled = true
    END IF 
    END FUNCTION

    Code:
    If CkISfilled(Document.Form.Tvenue.Value, Document.Form.Tevent.Value ) Then
    'It is true so do form processing
    Else
    'It is false we do not want to process
    End If
    Edit:
    I just realized you are using vbscript. I am not sure if my syntax is correct but the conept is.
    Last edited by allida77; 02-12-2003 at 06:53 PM.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Pretty close to what I'd do, but I wouldn't use VBScript client-side... what I would do:

    Code:
    <% @Language="VBScript" %>
    <% Option Explicit %>
    <%
    Dim Tvenue
    Dim Tevent
    Dim NumberOfTimesSubmitted
    
    Tvenue = Trim(Request.Form("Tvenue"))
    Tevent = Trim(Request.Form("Tevent"))
    NumberOfTimesSubmitted = Request.Form("NumberOfTimesSubmitted")
    
    '************************************ MAIN PROGRAM
    
    NumberOfTimesSubmitted = NumberOfTimesSubmitted + 1
    
    If Len(Tvenue) = 0 OR Len(Tevent) = 0 Then
    	Call DisplayForm()
    Else
    	Call ProcessInformation()
    End If
    
    '******************************** END MAIN PROGRAM
    
    '************************************* SUBROUTINES
    
    Sub ProcessInformation()
    	'Do whatever you want to do here...
    	Response.Write("YAY!")
    End Sub()
    %>
    
    <% Sub DisplayForm() %>
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    	"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
    	<title></title>
    </head>
    <body>
    	<div>
    		This would be your form with your input boxes with the appropriate names!<br /><br />
    
    		You'd also want to add a hidden field, called "NumberOfTimesSubmitted" before your submit button...<br /><br />
    	
    		Then, if <br /><br />
    
    		NumberOfTimesSubmitted > 1<br /><br />
    
    		When you redisplay your form using the subroutine "DisplayForm()", show the user an error!
    	</div>
    </body>
    </html>
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    New Coder
    Join Date
    Jan 2003
    Location
    N. Ireland
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks guys, i will try and get this to work, though it may take a few days....
    ....well just a few hours instead and it works a dream, thanks again whammy, fantastic! I had to give the hidden field NumberOfTimesSubmitted an initial value of 0 to get it to work as it kept giving a string: "" error. But there is no incrementing counter or anything on NumberOfTimesSubmitted so i have yet t o figure out how to display an error message.
    Last edited by skalag; 02-13-2003 at 03:41 PM.
    ska

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The incrementing counter is this:

    NumberOfTimesSubmitted = NumberOfTimesSubmitted + 1

    What you need to do is have a hidden field like this, right before your submit button:

    <input type="hidden" name="NumberOfTimesSubmitted" value="<% = NumberOfTimesSubmitted %>" />

    Then, it will pass it from page to page.

    To show an error, you can just do something like:

    <% If NumberOfTimesSubmitted > 1 AND Len(yourfield) = 0 Then %>
    <span style="color:#ff0000> *Required</span>
    <% End If %>

    Obviously there are a number of ways to do this, this is one simple method.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    New Coder
    Join Date
    Jan 2003
    Location
    N. Ireland
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks whammy i got it to work doing something similar ^, im off to think through the logic for my next problem now, which should be interesting. i have entered the date of an event in the database like this, day, date, month fields, as text eg. MON, 23rd, jun. But I now want to display data as ORDER by the date fields with the soonest being displayed first. Kind of impossible HUH! So i plan to write a function that will hopefully replace the date, month fields with a date that can be added to a date field like 23-06-03 in the database to order by when displaying data. I think it is possible to do this, but if it is a bad idea for any reason could you advise?
    ska

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, that sounds quite easy to me...

    You should use a DateTime field in Access or a shortdatetime or datetime field in SQL Server to store dates though, usually (instead of a text field), at least in my opinion, some people may differ in their opinion... however, for me that makes it very easy to sort by date or select a date range using a SQL statement later on using things like DATEDIFF() or DATEPART() right in the SQL Statement itself.

    As a matter of fact, I might look up DatePart() and DateDiff() on MSDN and w3schools.com if I were you. It definitely can't hurt to know this stuff...

    Also, you can probably write a function that pulls each "text" date in your database, splits it up (probably by comma since you're using that by a delimiter), and then creates a new "real" date from that information. Check out the CDate() function. Then you can update a new datetime field in your database for each record with the "true" date returned returned from your function (after you make sure that your function is really returning a valid date, of course!)... which should allow you get the kind of results you want much easier.

    Once you've updated all of the fields, and updated your scripts to NOT write to that text field anymore, I'd delete that field entirely, since a text date field is pretty much useless in many cases...

    P. S. In the future, you may also want to check out this code, it may help you get a quicker start when selecting date ranges in the first place:

    http://www.solidscripts.com/displayscript.asp?sid=18

    Not to mention it's a pretty compact way to display date dropdowns in classic ASP IMHO... and it also validates that a valid date was entered on the client side.

    If you do end up using it and need help validating the date on the server-side as well, it's not too hard. To validate the dates, you just call the IsDate() function of VBScript. Once you're sure they are both valid dates you can run a DateDiff() comparison against them or whatever... the reason you want to use IsDate() first is because DateDiff() will throw an error if you don't input valid dates into it.
    Last edited by whammy; 02-14-2003 at 11:47 PM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #9
    New Coder
    Join Date
    Jan 2003
    Location
    N. Ireland
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would have been easier to put a proper date field in at the start or go back and do it now, but now i have got too pigheaded to go back and change things, especially as every small change i make seems to have a seriously detrimental effect on all of my code....anyway it was for the fun and practice as well as the stubbornness, this is how i did it anyway, it works fine enuff even if it is really uneccessary and resource consuming code, but it took me a whole day to figure this little bit out, only problem is figuring out a reliable way to do the year as it means a lot of problems in the future..maybe just add a 'year' dropdown list to the form or something...

    Dim strmonth
    Dim strdate
    Dim stryear

    strdate = Trim(Request.Form("Tdate"))
    strmonth = Trim(Request.Form("Tmonth"))
    stryear = "03"

    ' format month, date and year for insert into DB formatdate field
    'from text boxes with 23rd & june, then add stryear and the result = 23-jun-03

    'month first
    IF Len(strmonth) > 0 THEN
    strmonth = "-" & Left(strmonth, 3) & "-"
    ELSE
    strmonth = somethingelsecompletelydifferent
    END IF

    'date next
    IF Len(strdate) > 3 THEN
    strdate = Left(strdate, 2)
    ELSEIF Len(strdate) <> 0 THEN
    strdate = 0 & Left(strdate, 1)
    ELSE
    strdate = ""
    END IF

    a sign of improvement in my efforts though, even though it took all day to get this far, my past problems were in inserting into database but somehow i suceeded first time by just going

    rstpubdata("Formatdate") = strdate & strmonth & stryear
    ska


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •