简体   繁体   中英

Submit HTML form and get radio button value without javascript or jquery

I am trying to implement Net Promoter Score survey through email body. As email clients don't allow Javascript. I want to submit the radio button value to a url that is defined in Form Action attribute.

But my question is how to know which radio button is checked, and how to submit it to a remote url ? and in which form will it be submitted ? ie name value pair or how ?

Note: I know how Jquery and Ajax. I want to achieve same things without using Ajax or Jquery or Javascript

A standard HTML form submission should handle this fine

Make sure your radio buttons all have the same name attribute, and give them all a different value attribute

Include an input with type="submit" and the resulting form submission should have NameOfAllRadioButtons = ValueOfSelectedRadioButton

I don't think I've ever been sent an email with form inputs in the body, which probably means there are a lot of clients that don't support them at all. You might be better off sending a link to take the survey in an actual web page.

According to this article: https://www.sitepoint.com/forms-in-email/ you should be able to use a standard html form in an email. Outlook will display the form messed up though.

To get radio value, just do this:

<form action="/yoururl.php" method="get">
    <input type="radio" name="question" value="answer1" checked> answer1<br>
    <input type="radio" name="question" value="answer2"> answer2<br>
    <input type="submit">
</form>

In your backend code, you will be able to do $_GET["question"] to get either answer1 or answer2.

On submit user will be redirected to another page and most client will probably ask for confirmation before redirecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM