Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

required="yes" message="that..." not working. Why? 1

Status
Not open for further replies.

josel

Programmer
Joined
Oct 16, 2001
Messages
716
Location
US
Howdy!

CFMX on W2k - URL
If you try the "Register" link and view source, you will find that the all attributes, scripts and functions are there but they are not doing a thing ...

I am able to submit, process the form via action page leaving all fields blank. My action page checks for one field (safety measure) and stops the submition.

Normally, the natural behavior is to get a message box and stay within current form/page.

What could I be doing wrong?

Please excuse the lengthly post but I figure that posting the code may help.

Thaks;


Jose Lereborus


***************** CODE SNIPET **********************
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="body">

<cfform name="regUser" action="registerProcess.cfm?action=add" method="post">
<tr>
<td width="40%" valign="top" align="right">
Your Company ID&nbsp;&##149;
</td>
<td width="60%">
<cfinput class="inputbg" name="CompCode"
required="yes" message="Need a valid company code!"
size="20" maxlength="20">
</td>
</tr>
<tr>
<td width="40%" valign="top" align="right">
Your Name&nbsp;&##149;
</td>
<td valign="top" width="60%" align="left">
<cfinput class="inputbg" name="UserName" type="text"
size="35" maxlength="50" required="yes"
message="Please enter user name!">
</td>
</tr>
<tr>
<td width="40%" valign="top" align="right">
Your User Code&nbsp;&##149;
</td>
<td valign="top" width="60%" align="left">
<cfinput class="inputbg" name="UserCode" type="text"
size="20" maxlength="20" required="yes"
message="Please enter user code!">
</td>
</tr>
<tr>
<td valign="top" align="right" width="40%">
Your Email&nbsp;&##149;
</td>
<td valign="top" align="left" width="60%">
<cfinput class="inputbg" name="Email" type="text"
size="35" maxlength="50" required="yes" message="You
must enter a valid email address!">
</td>
</tr>
<tr>
<td valign="top" align="right" width="40%">
Re-Enter Email&nbsp;&##149;
</td>
<td valign="top" align="left" width="60%">
<cfinput class="inputbg" name="Email2" type="text"
size="35" maxlength="50" required="yes" message="You
must cofirm your email address!">
</td>
</tr>
<tr>
<td valign="top" align="right" width="40%">
Your Password&nbsp;&##149;
</td>
<td width="60%">
<cfinput class="inputbg" name="password1" type="password"
size="20" required="yes" message="You MUST enter a
password!">
</td>
</tr>
<tr>
<td valign="top" align="right" width="40%">
Re-Enter Password&nbsp;&##149;
</td>
<td width="60%">
<cfinput class="inputbg" name="password2"
type="password" size="20" required="yes"
message="Please re-enter your password!">
</td>
</tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr>
<td valign="top" align="center" width="100%" colspan="2">
<input type="checkbox" name="NotifyMe" value=""
checked>&nbsp;Please notify me of changes and/or
answers!
</td>
</tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr>
<td colspan="2" valign="top" align="center"
width="98%">&nbsp;&##149;<font
size="2px">&nbsp;Required fields</font>
</td>
</tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr>
<td align="center" colspan="2" valign="top">
<input type="submit" value=" Add User ">
<input type="reset" value=" Reset Form ">
</td>
</tr>
</table>
</cfform>


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
josel, Hmmm, just by looking at it, I noticed a few things, these may not solve your problem, but nonetheless its worth a shot.

But first, next time you post a portion of code use the [ code ] tags?? Makes it easier to read. ;-)

1) Your <script> tags' function name is _CF_checkregUser(_CF_this). but in your <form> you're calling the function asonSubmit="return _CF_checkregUser(this)", try changin the "this" to "_CF_this" instead.

2) At the end of the first function, get rid of the return true;, you're returning true as it is in the onSubmit.

3) And lastly, your </form> is in the wrong place, move it before the </table>. HTML tags must follow sequence. So if you opened a <form> taf after the <table> tag, then the </form> comes first then the </table>, know what I mean??

Let us know what happens.


____________________________________
Just Imagine.
 
Hello GujuDet!

The scripts are produced by CFML, I do not write them in but, I will try changing the cfinput for input and just paste the script with changes as you suggest.

The calling command is simply passing a value (this) and the called function is receiving a parameter(_CF_this). It should not matter and their names should not need to be same. However, called function must use parameter name as defined. I think that (this) is the JS way to pass the object name, in this case, the form's name.

I once had problem closing cfform inside the table. The form just did not look/work ... By trial and error, I found that closing cfform after closing table, problem went away.

Where can I learn about using [ code ] tags for future postings? Can you post a sample of syntax?

Thanks;


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
josel, ummm, my name is GUJUm0deL (you wrote "GujuDet", :-))

OK, now onto business. Yeah the "this" is used to pass an object in JS, but I wasnt sure if CF required the passing of objects to be same as declared. Why not simply use the JS way of doing a simple validation?? Its a lot easier and maintenance is 10x easier then the CF way. I thought of using CF validations script but the further I looked into the more I got turned off, its just easier to go to with JS or VBScript.

CF follows the same code sequence as HTML, so if you opned one tag then another, then the second tag has to be closed before the first tag. If all else fails, simply use <form> and <input> then its CF counterpart. I always stick with the HTML way, its just much easier to deal with.

The [ code ] looks like this:

Code:
some code here by placing the code inside the [ code ] tags.  To see a list of examples, clicj the "Process TGML" link under the post boxes and a popup window tells you of the TGML that tek-tips uses.


____________________________________
Just Imagine.
 
Hello GUJUm0deL! Sorry about getting it wrong earlier ...

This is what I ended up using and it is doing a better job.

[
<script LANGUAGE=JAVASCRIPT TYPE="text/javascript" >

<!--
function validate()
{
var regUser = document.myForm;
var _errMsg = "";

// check mandatory fields
if (document.regUser.CompCode.value == "")
_errMsg +="\n- Company Code";
if (document.regUser.UserName.value == "")
_errMsg +="\n- User Name";
if (document.regUser.UserCode.value == "")
_errMsg +="\n- User Code";
if (document.regUser.Email.value == "")
_errMsg +="\n- Email Address";
if (document.regUser.Email2.value == "")
_errMsg +="\n- Confirm Email Address";
if (document.regUser.password1.value == "")
_errMsg +="\n- Password";
if (document.regUser.password2.value == "")
_errMsg +="\n- Confirm Password";

if (_errMsg == "")
{
document.regUser.submit();
}
else
{
_errMsg = "There was an error with the form. You need to address the following fields:\n" + _errMsg + "\n\nPlease correct any problems and try again";
alert(_errMsg);
return false;

}
}
//-->
</script>
]

This is more work for me but, it also forces me to learn things I would not otherwise. Now, I am off to find a way to make this work a bit more dynamic.

Regards;


Jose Lerebours



KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top