Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 8570 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I'll do this any way i have too, i'm not afraid of Javascript.

I need a form to produce an error if all fields are empty. Only one of the fields has to have anything in it, but it doesn't matter which field. Basically , now what i could do through FMP and CDML is have the format page have an If / Else Statement. From FM, a field returns "1" if any of the 10 fields are complete, 0 if nothing is entered. In CDML on the format page, If Field_Check.eq.0, ERROR BLAH BLAH BLAH, Else, SUCCESS BLAH BLAH BLAH.

But i'd rather not do this. I would rather it either, using built in FM validation, go to the -error page, or using javascript have a pop-up window say HEY MORON FOLLOW DIRECTIONS or some such.

So i can't figure out how to get built in FM validation to return and error for me in this case, and i suck at javascript (i pirate all my codes cool.gif" border="0 ). So if anyone could help, i'd greatly appreciate it.

Jeremy

Posted

Hi Jeremy,

if i have correctly understood your concern you have to check if your fields are empty or right filled; if thi is correct you can add to your db calculated fields (one per each checked field) then check the results via script assciate to a 'validate form button'.

I do an extensive use of this and, for me, it works well; for comments or other don't hesitate to contact me directly at my e-mail address.

Hope this helps.

Greetings from Holy Lands.

Posted

Well, i'm not sure if i understand you correctly this time. If you mean run an FM script over the web, i can't do that for various reasons. I need the page to either return the -Error page specified in the "FMPro Form 'headers' (invisibles)" or have a javascript alert before the user can continue.

I have used calculation fields, but i can't get FM to validate anything correctly for me.

Thanks for the input, but either i don't understand or we're on slightly different pages.

Greetings From the Free World cool.gif" border="0

Jeremy

Posted

There are loads of sites out there that let you paste form validation codes for adapting most come with instructions aswell smile.gif" border="0.

http://www.java-scripts.net

http://www.a1javascripts.com

etc etc.

superb for those who pirate

wink.gif" border="0

PS

I though i might as well add one!

remove all (NOTE: .........) bits before you try it!

code:


<script language="JAVASCRIPT"><!--

(NOTE: names the function to be called on the onSubmit action)

function validForm(NameofForm) {

(NOTE: checks if the field is empty)

if (NameofForm.FieldName.value==""){

(NOTE: this the message that will be displayed)

alert("You must enter data")

(NOTE: selects the form object so the user knows where the error is)

NameofForm.FieldName.focus()

(NOTE: if the 'if' statement above is true this stops the form submitting)

return false

}

(NOTE: if the 'if' statement above returns false then this allows the form to submit)

return true

}

// -->

</script>

(NOTE: Have your form tag like this.......)

<form name="NameofForm" action="FMPro or action.lasso" method="Post" onsubmit="return validForm(NameofForm)">

So for a <form name="passForm" etc...> and a text field <input type="text" name="forename"> you would have.......

<head>

<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">

<title>Welcome To My Field Validation Site</title>

<script language="JAVASCRIPT"><!--

function validForm(passForm) {

if (passForm.forename.value==""){

alert("You must enter your name")

passForm.forename.focus()

return false

}

return true

}

// -->

</script>

</head>

<form name="passForm" action="FMPro or action.lasso" method="Post" onsubmit="return validForm(passForm)">


Hope this helps

NB webmonkey.com has JavaScript tutorials which are very good!

I think i have typed correctly but there may be a typo in there somewhere

laugh.gif" border="0

[ May 25, 2001: Message edited by: flexistentialism ]

Posted

yeah, you could get a free one.. but my offer still stands to write one specifically for your form... all you have to do it post your HTML code..

well here, let me go ahead and post this one. it only works if you have nothing but text fields in your form though.. if you have any check boxes or anything like that it might screw it up..

code:


<HTML>

<HEAD>

<script language="javascript">

function validateform()

{

var element_num = document.FORMNAME.elements.length

var blanknum = 0

var totalnum = element_num - 1

for (var i = 0; i < element_num; i++)

{

if(document.FORMNAME.elements
.value == "")

{

blanknum = blanknum + 1

}

}

if(blanknum == totalnum)

{

alert("You must fill something in.");

return false

}

}

</script>

</HEAD>

<HTML>

<form name="FORMNAME" onSubmit="return validateform()">

<input type="text" size="10"><BR>

<input type="text" size="10"><BR>

<input type="text" size="10"><BR>

<input type="text" size="10"><BR>

<input type="submit">

</form>

</html>


oh and if you have any buttons on your form other than the submit button, such as a reset button or anything this one will need to be changed just a bit..

[ May 25, 2001: Message edited by: bman ]

Posted

Wow, guys, thanks. yeah, trust me, i use those sites on a pretty regular basis, but i didn't have a lot of time to search yesterday for something like that. I spent about five minutes browsing and then i thought, "Ya know, i bet if I post this in FMForums, BMan will be all over this. . ." so i did, and he was. cool.gif" border="0

As for your code, flex, i don't write javascript, but i can read it a little (which goes to show that if i ever get the time i can probably learn it pretty quickly), and when reading yours, i don't quite see how it is checking that one of the ten fields has a value. It seems to be checking specific required fields, but what i need is not specific, just one of whichever they want to choose. I may be completely wrong though.

No Matter, though, BMan, if you're offering for free, i'm sending the file via email. It's quite a bit (30+ fields) so posting it would be silly. I'll be glad to help you out in some way as best i can, but as for monetary value, that won't be happenin' (sorry bud). We can discuss anything else further in emails.

Thanks again:

Jeremy

Posted

yaf.. if you sent it through e-mail i will have to get to it tonight because that is my home e-mail address.. an i am not home right now..

but i will look at it as soon as i get there..

as for the code above what it does it loop through all the fields and check to see if they have a blank value.. if all of them have blank values it gives and alert.. however like i said it will only work if all the fields in the form are texts fields and you only have a submit button on the form.. putting anymore buttons can mess it up, but it can be easily fixed.. but i will take a look tonight.. it shouldn't take me more than a few minutes to edit the code i sent you to work for your form..

if you want to lean Javascript.. there is a nice tutorial at http://www.htmlgoodies.com i took that tutorial and then i hung around the javascript city forums for awhile.. http://www.javascriptcity.com

thats how i learned.. but i am far from an expert.

Posted

I do kindof what you want and changed the logic for your app:

function validate(){

if ((document.Audit.Evaluator.value=="")

&&(document.Audit.Operator.value=="")

&&(document.Audit.Date_Performed.value=="")

&&(document.Audit.Process_Cell.options[document.Audit.Process_Cell.selectedIndex].value=="")

&&(document.Audit.Evaluation_Type.options[document.Audit.Evaluation_Type.selectedIndex].value=="")

&&(document.Audit.Evaluation_Method.options[document.Audit.Evaluation_Method.selectedIndex].value=="")

&&(document.Audit.Process_Status.options[document.Audit.Process_Status.selectedIndex].value=="")

&&(document.Audit.Personnel_Verification.options[document.Audit.Personnel_Verification.selectedIndex].value=="")

&&(document.Audit.Tooling_Verification.options[document.Audit.Tooling_Verification.selectedIndex].value=="")

&&(document.Audit.Process_Verification.options[document.Audit.Process_Verification.selectedIndex].value==""))

{

alert ("You must fill in something.")

return false

}

Posted

dpsires.. that will work.. but that way you have to tell it to look at each form element by name.. if you change the form in anyway you must go back and also change the code... and with the 30 fields that Yafreax says he has than that code you gave is going to br problematic.. would take quite awhile to trouble shoot if you misspelled one of the names of the form elements..

Posted

yafreax you are correct the bit of script I added does indeed only check for one form element by name I just repeat the if statement within the function changing the form element name....I personally prefer doing it this way because of the reasons outlined by dspires.

Also it lets you change the alert for each form element and bring that form element into focus and/or select the data in it. I prefer that to just saying "something in the form isn't done right find it".

laugh.gif" border="0

[ May 25, 2001: Message edited by: flexistentialism ]

Posted

bman, actually, the code refers to the fields by their names so it will work even if the form is changed around. For instance if another field is added anywhere on the form that doesn't require validation, there is no need to go back and change the validation script.

I have used the form element index approach in the past. A problem comes up when you add any field, button, etc. in the top of the form it will cause all subsequent numbers to increment.

My approach allows easier arrangement of the form and elements withing the form to satisfy customer requests.

There are only 10 elements out of about 30 on my form that require validation, the same number as on yafreax's original post.

I agree though that if all elements within a form require validation, your approach would be preferred.

Posted

yes, flex, i've used the same type thing, difference this time is that i CAN"T be specific. If i'm specific, i won't get the results i need. For example, lets say you have the chance to order either CD, Tape Or 8-Track smile.gif" border="0, listed in that order. you have to order at least one, but it doesn't matter which one. If you wanted to order the 8-track, you'd place your qnty in the field, on submit an alert would show "You have not placed an order for a CD." Well, you didn't want a CD. I would only need an alert if you didn't have any of the qnty's completed.

BTW, spires, 10 was just my original example, it does have to check through 30 fields. Unfortunately they use Pop-Ups so i don't know if BMan will have the answer for me. The site has already "Gone Live" and the users haven't said anything about it yet, so i'm okay for now.

Just thought i'd try and clear that up, flex. Of course, it may be me that is actually missing the point.

jeremy

Posted

quote:

Originally posted by yafreax:

yes, flex, i've used the same type thing, difference this time is that i CAN"T be specific. If i'm specific, i won't get the results i need. For example, lets say you have the chance to order either CD, Tape Or 8-Track
smile.gif" border="0
, listed in that order. you have to order at least one, but it doesn't matter which one. If you wanted to order the 8-track, you'd place your qnty in the field, on submit an alert would show "You have not placed an order for a CD." Well, you didn't want a CD. I would only need an alert if you didn't have any of the qnty's completed.

BTW, spires, 10 was just my original example, it does have to check through 30 fields. Unfortunately they use Pop-Ups so i don't know if BMan will have the answer for me. The site has already "Gone Live" and the users haven't said anything about it yet, so i'm okay for now.

Just thought i'd try and clear that up, flex. Of course, it may be me that is actually missing the point.

jeremy

yafreax,

I'm a little confused as to the need to generate an error code and go to the error page, plus combining that with javascript. When it comes to javascript I'm a complete novice as well, but I wouldn't use a complicated javascript here either, especially when there is a simpler method to use.

I would create one calculated field, that checks all the fields you want 'validated' and display a result of 1 or 0 depending on whether any field has an entry or all are empty. The results form would have an if then:

If calculated field has 1, then whatever.

If calculated field has 0, then javascript to pop up or simple error message.

it works and it's simple. You don't really want to set an actual Validation rule in Filemaker for this, because if you get an error, Filemaker leaves the record blank and the user has to start over again. It causes problems. The above method solves your problem, it's simple, if you add fields you just have to edit one calculated field and make no changes whatsoever to the cdml form. It's perfect and low maintenance, which is how your webpages should be.

The only thing is if you need to KNOW which field(s) were not entered in, but from what you write, it's not specific, so you don't need this. What do you think?

crazy.gif" border="0

This topic is 8570 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.