Re: Input form strategy?

From: Date: Wed, 18 Oct 2000 04:57:03 +0000
Subject: Re: Input form strategy?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20787@lists.php.net to get a copy of this message
Hey Todd: > $redo = $HTTP_GET_VARS[redo]; > > if ($redo) { > $firstname = $HTTP_GET_VARS[firstname]; > $lastname = $HTTP_GET_VARS[lastname]; > } else { > $firstname = ""; > $lastname = ""; > }; Well, first off, that can be rewritten by dropping the first line and then continuing: if ( ! isset($redo) ) { $firstname = ""; $lastname = ""; } You don't need the "$firstname = $HTTP_GET_VARS[firstname];" All you need to do is refer to $firstname directly. But, what are you trying to do here? If you have $redo set, check the form? What do you want to check for? Anyway, allow me to ignore what you're doing and take a different tack... <?php function FormGenerator() { global $first; global $last; echo "<form method=\"post\" action=\"test.html\">\n"; echo "first: <input type=\"text\" name=\"first\" value=\"$first\" />\n"; echo "<br />last: <input type=\"text\" name=\"last\" value=\"$last\" />\n"; echo "<br /><input type=\"submit\" name=\"Submit\" value=\"Find\" />\n"; echo "</form>"; } # Was a form submitted? if ( isset($Submit) ) { # Yes. Check input. $Problem = 0; if (! strlen( $first = ereg_replace("[^A-Za-z]", "", $first) ) ) { echo "<h3>Enter first name</h3>"; $Problem++; } if (! strlen( $last = ereg_replace("[^A-Za-z]", "", $last) ) ) { echo "<h3>Enter last name</h3>"; $Problem++; } if ($Problem) { FormGenerator(); exit(); } # Cool. Everything's okay, continue... # Now, do whatever you want with the user input, like echo "Hi $first $last!"; } else { # No. Print the form. FormGenerator(); } ?> -- PHP scripts that make your job easier http://www.analysisandsolutions.com/code/ SQL Solution | Layout Solution | Form Solution T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#20787) next »