Form Require Hidden Input Not Working

T

tea-mad brit

The last input in my form is hidden.
<input type="hidden" name="required" value="name,email,phone,organization"/>
I have been out of the loop with writing code for a while. This validates,
but does not work. I am trying to avoid a user clicking on the send button
and submitting a blank form. The form goes to a PHP handler and all that
works fine.
Any thoughts?
Thanks
 
E

Ed Jay

tea-mad brit said:
The last input in my form is hidden.
<input type="hidden" name="required" value="name,email,phone,organization"/>
I have been out of the loop with writing code for a while. This validates,
but does not work. I am trying to avoid a user clicking on the send button
and submitting a blank form. The form goes to a PHP handler and all that
works fine.
Any thoughts?
Thanks

You might try using onsubmit="return somefunction();" and having
somefunction() check the form field(s) for empty. If the form is empty,
return false. If the form isn't empty, return true.

If you want, using innerHTML, you can have somefunction() print an error
message to the screen before returning false..
 
D

David Dorward

tea-mad brit said:
The last input in my form is hidden.
<input type="hidden" name="required"
value="name,email,phone,organization"/>

If you plan to serve your XHTML as text/html[1], then appendix C requires a
space before that /.
I have been out of the loop with writing code for a while. This validates,
but does not work. I am trying to avoid a user clicking on the send button
and submitting a blank form. The form goes to a PHP handler and all that
works fine.

What that code should do is submit to the server side script the data in the
value attribute attached to the key that is the value of the name field.
Nothing about it actually makes any fields required.

The server side script can then check what values were submitted based on
that field and complain to the user if they haven't entered the required
values.

You could also do something similar with client side JavaScript.

Either way, user's can modify the required input if the want to, so its no
good if you really want to prevent people not submitting those fields.
(OTOH, it does make it rather difficult for the user to have a successfully
processed form by accident).

[1] If you don't then you are going to have a really limited audience, if
you do then there isn't any point in using XHTML instead of the better
supported HTML 4.01 in the first place.
 
T

tea-mad brit

Either way, user's can modify the required input if the want to, so its no
good if you really want to prevent people not submitting those fields.
(OTOH, it does make it rather difficult for the user to have a
successfully
processed form by accident).

[1] If you don't then you are going to have a really limited audience, if
you do then there isn't any point in using XHTML instead of the better
supported HTML 4.01 in the first place.

Yes, I just need to help the user avoid a mistake and get a false count on
how many people fill out the form.

I don't know anything about JS but a little PHP. If I understand correctly,
I need to modify the server side script and that the required stuff in the
input form isn't doing anything?
Thanks.
 
D

David Dorward

tea-mad brit said:
I don't know anything about JS but a little PHP. If I understand
correctly, I need to modify the server side script and that the required
stuff in the input form isn't doing anything?

The required stuff in the input form is providing data that gets sent to the
server. The server side script could use this to decide what to test for in
its sanity checking routines.
 
G

gerg

David said:
tea-mad brit wrote:




The required stuff in the input form is providing data that gets sent to the
server. The server side script could use this to decide what to test for in
its sanity checking routines.

use something like this:

processor.php

<?

session_start();

// the $_POST variables should be the same as your form names.

if( (empty($_POST['email'])) || (empty($_POST['name'])) ||
(empty($_POST['phone'])) ){

// return to the form and display an error message.

$_SESSION['errormessage']="Please fill out all form fields.";
header("Location:http://www.mysite.com/myform.php");
exit();

}
else
{
// execute code that should happen if all fields are filled in.
}

?>


myform.php

<?

//this line makes available any session variables already set, like the
error message above.

session_start();

//if there is an error message available, display it

if($_SESSION['errormessage']){
echo $_SESSION['errormessage'];
}

?>

Your form would then go here.

Hope that helps.

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top