Page 1 of 1

validation script not working on Include

Posted: Thu Jun 14, 2012 11:20 am
by LarsUlrich
Hi, I think I need help with this.
Once I had a php in which a validation script for a form worked ok.
It looked something like this:

Code: Select all

<head>
<script>
function checkform()
{
if (something) {
return true;
}
}
</script>
</head>
<body>
<form name="xx" form action="xx.php" method="post" onSubmit="return checkform()">
here form stuff
</form>
</body>
As I said, form validation here was OK.

Now I changed the rationale of the page, and the validation script is in a file separeted from the Form, and I joint this two files with the "include" statement. This operation is performed by the Handler.php. Something like this:
Handler.php:

Code: Select all

<?php
if (something) {
include 'Header.php';
include 'WhereFormIs.php';
}
?>
Header.php:

Code: Select all

<head>
<script>
function checkform()
{
if (something) {
return true;
}
</script>
</head>
WhereFormIs.php:

Code: Select all

<body>
<form name="xx" form action="xx.php" method="post" onSubmit="return checkform()">
here form stuff
</form>
</body>
I thought that "including" several pieces of code work as a whole (for example, link to CSS is in the "Header.php", and is correctly assigned to the others pieces conforming the page).
My question is:
Is this last concept correct?
Thanks in advance.

Re: validation script not working on Include

Posted: Thu Jun 14, 2012 12:41 pm
by social_experiment
LarsUlrich wrote:Is this last concept correct?
If you are refering to including files then yes; one reason is that you only have to create one file but can use it across a few by including it everywhere you want to use it.

Re: validation script not working on Include

Posted: Thu Jun 14, 2012 1:27 pm
by LarsUlrich
Thanks S_E.
Then something else is wrong, cause the form fails to validate.
I will revise my code.
Thanks again.