I recently stumbled over XForms (W3C 1.1, ODK XForms) and I struggle to see how they are used (if they are still used).
The SO tag page says:
XForms is an XML format that specifies a data processing model and user interface for the XML data. Eg. web forms.
Now I looked at the W3C examples and I don't see any kind of user interface. It's just XML that is displayed there.
What I do
When I want to have a form in the web, then I have to sides to work on: The front-end and the back-end. The front-end is either writing directly using <form> / <input> /
` HTML elements and CSS for styling or generating those with packages like flask-wtf.
The back-end listens to GET / POST HTTP-requests to receive the form.
Question
I have a lot of beginner questions. My main question is How are XForms used?. A minimal Python example would be of most value to me. Maybe something simple like a registration form: A username field, a password field and a password confirmation field could show this.
I would create HTML like this:
<form action="" method="POST">
<label for="username">Username</label>
<input type="text" name="username" id="username" />
<label for="pw">Password</label>
<input type="password" name="pw" id="pw" />
<label for="pw2">Confirmation</label>
<input type="password" name="pw2" id="pw2" />
<input type="submit" />
</form>
And with Flask the backend could look like this:
# Third party modules
from flask import redirect, url_for, render_template
from flask_login import current_user
from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField, SubmitField
# First party modules
from my_db_models import User
class LoginForm(FlaskForm):
email = StringField("Email")
password = PasswordField("Password")
submit = SubmitField("Log In")
@auth.route("/login", methods=["GET", "POST"])
def login():
if current_user.is_authenticated:
return redirect(url_for("main.index"))
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data).first()
if user is None or not user.check_password(form.password.data):
flash(INVALID_EMAIL_OR_PASSWORD, "error")
return redirect(url_for("auth.login"))
login_user(user, remember=form.remember_me.data)
return redirect(url_for("index"))
return render_template("login.html", form=form)
How would that look with XForms? Where exactly is a typical use-case for XForms? What are they comparable to? Are XForms only used in Java? (I have seen Python packages, but I have never heard of them)