Re: validate a tag
| From: | Ben Ramsey | Date: | Tue, 05 Oct 2004 14:23:35 +0000 |
| Subject: | Re: validate a tag | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198674@lists.php.net to get a copy of this message | ||
I just glanced at your code, and your usage of empty() looks correct and should work just fine. However, you're calling the function recursively (from within itself), so you'll probably wind up in a loop. Pull that test out and do it at the top of your script instead of within the function.
I've also found that empty() sometimes doesn't work well with form values, so you may want to test with (strlen(trim($HTTP_POST_VARS['question'])) > 0) instead.
Pahlevanzadeh Mohsen wrote:
Dear,I have a input text tag that it named question. Also i have a 2 radio bottum. When i receive their value,I want to test that question tag is empty or not.If empty,I again send to client until client fill out this tag. Can u solve my problem? <?php function display_form() { echo "<form action=\"".$_SERVER['PHP_SELF']. "\" method=\"post\">"; echo "Your question<input type=\"text\" name=\"question\" "><br />"; echo "radio type <input type=\"radio\" name=\"type_of_reply\" value=\"0\"><br />"; echo "check box type <input type=\"radio\" name=\"type_of_reply\" value=\"1\"><br />"; echo "<input type=\"submit\">"; /* if (empty($HTTP_POST_VARS['question']))-- Regards, Ben Ramsey http://benramsey.com --------------------------------------------------- http://www.phpcommunity.org/ Open Source, Open Community Visit for more information or to join the movement. ---------------------------------------------------{ echo "please fill out question field."; display_form(); }//end of if*/}//end of display_form func function test_var() { if (empty($HTTP_POST_VARS['question'])){ echo "please fill out question field."; display_form(); }//end of if}//end of func function insert_to_question() { display_form(); while(empty($HTTP_POST_VARS['question']))test_var();}//end of insert_to_question func insert_to_question(); ?>