Click to See Complete Forum and Search --> : form submit


sandro27
10-30-2004, 05:57 PM
Hello world !!

I have finished my form validation but the PHP script is sending the information to the database without validating it.

How can I solve this problem?


JS is:
<Script Language=JavaScript>
function validate(isForm){...



and the PHP is:

<?
if($_POST['submit']){ ...

form action="" method="post" enctype="multipart/form-data" name="myForm">

<input type="submit" name="submit" value="Submit >>" onclick="validate(myForm)">


All in this order.

Hope for help

Cheers

Sandro27

Charles
10-30-2004, 06:10 PM
Your opening SCRIPT tag should look like <script type="text/javascript"> and you script should return true if everything is fine, false if not.

Your opening FORM tag should look like <form action="some-script.php" method="post" enctype="multipart/form-data" name="myForm" onsubmit="return validate(this)">.

Your submit button should look like <input type="submit" name="submit" value="Submit &amp;gt;&amp;gt;"> or <button type="submit">Submit &amp;gt;&amp;gt;</button>.

If that doesn't sort things out then give us the URL.

sandro27
10-30-2004, 08:33 PM
I am still having problems.

The script validation warning comes out but the information is going to the database without validating it.

Maybe if you could look at http://www.brasiltravel.com/FIG/join3.php

Thanks

Sandro

Charles
10-30-2004, 09:04 PM
Your function "isForm" needs to return true to submit the form and false to suppress submission. It should not try to submit the form.

sandro27
10-30-2004, 09:12 PM
Thanks. Would you be able to explain it by showing the code am I supposed to use?

Charles
10-30-2004, 09:14 PM
Try replacing if (isValid){myForm.submit()} with return isValid.

sandro27
10-30-2004, 09:29 PM
Well, I did that. But it is giving an error message at the bottom and the info still goes to the database.

should I type only return isValid; to replace if (isValid){myForm.submit()}}?

sandro27
10-30-2004, 10:48 PM
When I use:

if (isValid){myForm.submit()}

the information is sent

but when I change for:

return isValid;

nothing happens

why is that?

7stud
10-30-2004, 11:47 PM
but when I change for:

return isValid;

nothing happens

What exactly are you changing? Post what the statement was before the change, and post what you changed it to.

Charles
10-31-2004, 06:18 AM
See the attached.

sandro27
10-31-2004, 06:48 AM
Thanks a lot Charles. Your file worked perfectly!! In fact it is even better than before.

Sandro 27

sandro27
10-31-2004, 11:26 AM
I have tried to use the form inside tables and cells for nice layout, but it happens that the script does not validate the form. Why it does happen?

Sandro27

sandro27
10-31-2004, 11:32 AM
The URL is http://www.brasiltravel.com/FIG/join5.php in case anyone would like to check it.

Cheers

Charles
10-31-2004, 12:13 PM
Originally posted by sandro27
Why it does happen? Perhas because you're not supposed to use TABLEs for layout.

sandro27
10-31-2004, 02:07 PM
So is it impossible to desigh the form like that?

I have seen websites using table for layout.

Sandro27

sandro27
10-31-2004, 03:31 PM
I have saw this form using tables at:

http://www.zerodegrees.com/zdapp/action/doRegister

How can I do the same with similar layout?

Thanks

Sandro27

Charles
10-31-2004, 04:12 PM
And just look at all of the errors on that page ( http://validator.w3.org/check?verbose=1&uri=http%3A//www.zerodegrees.com/zdapp/action/doRegister ).

The rounded corners are a bit tricky, but you should have no trouble doint the rest with CSS.

sandro27
10-31-2004, 05:01 PM
So you think I should give up trying to use tables for layout in my form? Any advise to make it look better?

Charles
10-31-2004, 05:04 PM
With CSS the possibilities are limitless - except that you'll have to wait untill CSS3 for rounded corners.

sandro27
10-31-2004, 05:07 PM
Humm. I see your point. So I should forget about tables and stuff for designing my pages and concentrate on CSS ...Is this the way to become a modern web developer?

Charles
10-31-2004, 05:19 PM
Originally posted by sandro27
Is this the way to become a modern web developer? I suppose, if you consoider that the post-modern age is almost over. Fron the HTML 4.0 Spec of 1998
Tables should not be used purely as a means to layout document content as this may present problems when rendering to non-visual media. Additionally, when used with graphics, these tables may force users to scroll horizontally to view a table designed on a system with a larger display. To minimize these problems, authors should use style sheets to control layout rather than tables.
http://www.w3.org/TR/1998/REC-html40-19980424/struct/tables.html#h-11.1

sandro27
10-31-2004, 05:24 PM
Great. Thanks for the advice !!!

sandro27
10-31-2004, 09:02 PM
I have one more question.

How can I validate a check box like:

<script type="text/javascript">
<!--
String.prototype.isEmailAddress = function () {return /^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/.test(this)}

function validate (f) {
var e, i = 0;
while (e = f[['user-name', 'email', 'confemail', 'password', 'confpassword','level'][i++]]) {
if (!/\S/.test(e.value)) {alert (['Field ', e.previousSibling.data, 'is required.'].join ('')); e.focus(); return false}
}
}
// -->
</script>

<input name="level" type="checkbox" id="level" value="2">

In this case, the check box is mandatory

Cheers

Sandro27