Loading ...
Sorry, an error occurred while loading the content.

Re: preventing empty vote in form

Expand Messages
  • 9el
    ... You just need to do basic form validation. The way you thinking is client side form validation. Showing the submit button after input is made, cannot be
    Message 1 of 3 , Oct 6, 2008
    • 0 Attachment
      >>Posted by: "Tedit kap" teditkap@... teditkap
      >>Sun Oct 5, 2008 6:48 pm (PDT)
      >>Hello,
      >>
      >>I have a radio button style poll form, currently even if a >>user does not select a choice and hits the submit button, >>his answer is submitted to my database as an empty >>response, which I dont want. I want everyone to vote and >>only then the submission should work. I thought about >>not displaying the submit button before he votes, but >>then it did not seem like a good idea. I want the submit >>button displayed before he votes, but if he clicks it >>before voting, it should prevent the response to be sent >>to the database. Any ideas on how to do that?
      >>
      >>Here is the submit button:
      >>
      >>echo "<input type=\"submit\" value=\"submit my >>answer\"/>";
      >>
      >>and, if it matters, here is how i display the choices >>before that:
      >>
      >>for($i=1; $i<=$qtotal; $i++)
      >>
      >>{
      >>
      >>$answer="answer".$i;
      >>echo "<input type=\"radio\" name=\"answer\" >>value=$answer>";
      >>echo $questions[$i];
      >>echo "</br>";
      >>
      >>}
      >>
      >>Thanks
      >>
      You just need to do basic form validation. The way you thinking is
      client side form validation. Showing the submit button after input is
      made, cannot be implemented from PHP well or not necessary for the
      purpose you want to do.

      First of all, PHP is server side language. If you do the basic steps
      of form validation. Like check
      if isset($_POST['submit']) == true then do the validation of inputs
      if the $_POST have a necessary input pattern present they are eligible
      to be inserted to DB.
      Search through google, php_manual, elementary php books for the Form
      Validation. The basic lesson will solve your problem perfectly well.

      9el
    Your message has been successfully submitted and would be delivered to recipients shortly.