/    Sign up×
Community /Pin to ProfileBookmark

prevent empty submission in radio button form

Hello,

I have a radio button poll form. Right now, 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

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@opifexOct 05.2008 — validate the form client side with js OR server side OR both.
×

Success!

Help @ketanco spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...