Re: validate a tag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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'])) { 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();
?>


-- Regards, Ben Ramsey http://benramsey.com

---------------------------------------------------
http://www.phpcommunity.org/
Open Source, Open Community
Visit for more information or to join the movement.
---------------------------------------------------

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux