简体   繁体   中英

How to run python function once user inputs into form field

I am an html page with a form to enter your email:

<!DOCTYPE html>
<html>
<body>

<h1>The form novalidate attribute</h1>

<p>The novalidate attribute specifies that the form data should not be validated when submitted.</p>

<form action="/action_page.php" novalidate>
  <label for="email">Enter your email:</label>
  <input type="email" id="email" name="email" required><br><br>
  <input type="submit" value="Submit">
</form>

<p><strong>Note:</strong> The novalidate attribute of the form tag is not supported in Safari 10 (or earlier).</p>

</body>
</html>

Is there a way to run a python script when the user enters his email address and then takes the input and runs it through this def function:

def send_email():
email_address=form_input
print(email_address)

So basically, when a user enters an email in the form, it takes the value and runs it through the send email function. I am new to using python with html so the syntax is confusing me. Any ideas or suggestions as to how to but it in the html file?

No, it is not possible to do it just in html. If you use.php as backend script, read this php form handling If you want to use python as backend script, you need to use ajax, eg ajax intro . In this case, need to run web server that take ajax request and respond the request

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