PHP Value Check
ok...this is a side thread of the one about JS Disabling...i decided to do this by PHP...same idea: if the "single" is empty (family is then selected), then at least child1 must have something in it...but if "family" is empty (single is selected), then all the "child" (child1 thru child4) must be empty as well...heres what i came up with, but it comes up with a parse error:
<?php
display_errors=true;
if (
if (!trim(document.form.getelementbyid(single).value));
if (!trim(document.form.getelementbyid(child1).value));
header(\"Location: http://.../family.html\");
);
elseif (
if (!trim(document.form.getelementbyid(single).value));
if (!trim(document.form.getelementbyid(child2).value));
header(\"Location: http://.../family.html\");
);
elseif (
if (!trim(document.form.getelementbyid(single).value));
if (!trim(document.form.getelementbyid(child3).value));
header(\"Location: http://.../family.html\");
);
elseif (
if (!trim(document.form.getelementbyid(single).value));
if (!trim(document.form.getelementbyid(child4).value));
header(\"Location: http://.../family.html\");
);
elseif (
if (!trim(document.form.getelementbyid(family).value));
if (!trim(document.form.getelementbyid(child1).value)=!);
header(\"Location: http://.../single.html\");
);
elseif (
/* Form Processing Code Goes here, I know that works... */
?>
necrotic posted this at 02:24 — 22nd July 2003.
He has: 296 posts
Joined: May 2002
You're trying to use JS in PHP, you can't. Sadly, you can't check forms until it is submitted. So, something like this:
form:
<form method='post' action='form.php'>
<input type='text' name='single' value='single'><br>
<input type='text' name='child1' value='child1'><br>
<input type='text' name='child2' value='child2'><br>
<input type='text' name='child3' value='child3'><br>
<input type='text' name='child4' value='child4'><br>
<input type='text' name='child5' value='child5'><br>
<input type='submit'></form>
Then the PHP processor:
<?php
if ((!trim($_POST['single']))&&(!trim($_POST['child1']))) {
header(\"Location: http://.../family.html\");
} else if ((!trim($_POST['single']))&&(!trim($_POST['child2']))) {
header(\"Location: http://.../family.html\");
} else if ((!trim($_POST['single']))&&(!trim($_POST['child3']))) {
header(\"Location: http://.../family.html\");
} else if ((!trim($_POST['single']))&&(!trim($_POST['child4']))) {
header(\"Location: http://.../family.html\");
} else if ((!trim($_POST['single']))&&(!trim($_POST['child5']))) {
header(\"Location: http://.../family.html\");
} else {
// Other Stuff
}
?>
I don't know what your trying to do with trim(). It doesn't return true or false, just a value without whitespace. More
Hope I helped.
[James Logsdon]
ShaneS posted this at 20:39 — 23rd July 2003.
They have: 93 posts
Joined: Jun 2003
You can do it with JS just as easily and never have them reload the page. Especially with CSS, you can alert them, change the field color to red, and then give them focus. JS is great for error checking up front and never leaving.
PHP requires you to have the page submitted and then it would have to be alter before display again to show errors.
[Design Alpha] -Web Services : Design,Hosting,Advertising,Software
Ask about custom pricing on hosting!!
Site Assets: [UltraGaming.com] [Blades of Warcraft]
kb posted this at 23:25 — 23rd July 2003.
He has: 1,380 posts
Joined: Feb 2002
i know...
thanks james
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.