validation script not working on Include

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LarsUlrich
Forum Newbie
Posts: 11
Joined: Tue Jan 03, 2012 12:45 pm

validation script not working on Include

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: validation script not working on Include

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
LarsUlrich
Forum Newbie
Posts: 11
Joined: Tue Jan 03, 2012 12:45 pm

Re: validation script not working on Include

Post by LarsUlrich »

Thanks S_E.
Then something else is wrong, cause the form fails to validate.
I will revise my code.
Thanks again.
Post Reply