There is probably an incredibly simple solution for this problem, but
I can't seem to figure it out. Hopefully one of you gurus can help.
I'm was messing around with PHP today and I wrote a tiny app that asks
for your name and zipcode. If your zipcode is less than 5 characters,
it asks you too enter a zip code with the proper amount of characters.
Here's the code:
<code>
<?php
print <<<_HTML_
<form method='POST' action='$_SERVE R[PHP_SELF]'>
Name: <input type='text' name='name'><br /><br />
Zipcode: <input type='text' name='zipcode'> <br /><br />
<input type='submit' value='Step 2...'>
</form>
_HTML_;
$zipcode = trim($_POST['zipcode']);
$zip_length = strlen($zipcode );
print $_POST['zipcode'];
if ($zip_length != 5){
print 'invalid amount of characters';
} else {
print ' ';
}
?>
</code>
I cannot figure out how to have the the 'invalid amount of characters'
string post only after the info is passed through the form. Instead it
displays that string on the bottom of the page without any
intervention. I know the answer is sitting right in front of my face.
Maybe someone can help?
Thanks!
I can't seem to figure it out. Hopefully one of you gurus can help.
I'm was messing around with PHP today and I wrote a tiny app that asks
for your name and zipcode. If your zipcode is less than 5 characters,
it asks you too enter a zip code with the proper amount of characters.
Here's the code:
<code>
<?php
print <<<_HTML_
<form method='POST' action='$_SERVE R[PHP_SELF]'>
Name: <input type='text' name='name'><br /><br />
Zipcode: <input type='text' name='zipcode'> <br /><br />
<input type='submit' value='Step 2...'>
</form>
_HTML_;
$zipcode = trim($_POST['zipcode']);
$zip_length = strlen($zipcode );
print $_POST['zipcode'];
if ($zip_length != 5){
print 'invalid amount of characters';
} else {
print ' ';
}
?>
</code>
I cannot figure out how to have the the 'invalid amount of characters'
string post only after the info is passed through the form. Instead it
displays that string on the bottom of the page without any
intervention. I know the answer is sitting right in front of my face.
Maybe someone can help?
Thanks!
Comment