Echo not working

Just trying to figure something out. I have a php page with a form on it. The form is set to

<form action="validator.php" method="post">

the forms submit button is

<td><input type="submit" value="submit" /></td>

In validator.php I do

if(isset($_POST['submit']))
{
$error= "HELLOELEOLE";
echo $error;

}

SHould the word HELLOELEOLE be printed out on a new page when I press submit? If I print something before the isset, it works, but it not printing anything inside the isset would tend to suggest it never gets into it. Am I doing something wrong?

cheers

No.

Only input elements with a NAME attribute get sent with the form.

lol, I just figured that out.

I do have another question. If the user enters incorrect information, I want it to display an error on my form.
If I have my form have an action though, this brings up a new php file. For the validation, can I do something like onsubmit = “Validator.php” and in the php file store the errors in a variable, and then in the form page, print out this variable?

Well, there are two ways to go about this;

#1: Have the form point at itself as the action, and then redirect/includeanddie if successful;
#2: Have AJAX parse the data, and return the results to be analyzed by javascript on the page.

You cannot call PHP directly with javascript. They occur at different points in the command cycle.

Just to clarify, is onsubmit only used for javascript files and not php files? If I do your first option, everything will be in one php file.

If possible, I want one php file with the form. When submit is pressed, another php file checks the data from that form. If there is an error, it sends the error back to the original php file to print out the error. If I can use onsubmit, this shouldnt be a problem. If I cant, the action will have to call up the second php file. But then as I say, this means a new page will open. Is there any way I can achieve what I want to do by having 2 seperate php files, but only one of them is used for display?

cheers

But why? There’s nothing wrong with having the processing code on the one page itself (unless you need to use it for multiple forms). Seems neater that way to me. You just make the action:

action="<?php $_SERVER['PHP_SELF'] ?>"

But if it must be a separate file, you could echo the form on the validator.php page with the errors listed above the form or inline with each form field. But you would end up on that page.

Doing it with Javascript/AJAX is less favorable, as it could be intercepted easier. Nothing wrong with it, but dont rely on it as your only verification.