Skip to content

Commit be65fa8

Browse files
Merge pull request #1097 from Iamtripathisatyam/main
Registration Form Web App
2 parents 9ca7bd1 + 41bb3ce commit be65fa8

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Overview:
2+
With the help of the PyWebIO module, we'll create a registration form. This Python library is mostly used to build simple, interactive web interfaces locally. Username, name, password, email, and website link information will be entered into this form. In relation to passwords, it will also double-check your password to see whether it is accurate. Your phone number, website URL, and email address will also be verified.
3+
4+
## Form Elements
5+
* input_group: Used to get the inputs in the group.
6+
* input: Used to take all kinds of inputs from the user.
7+
* type: This depends on user choice whether the user wants a number in the input or a text in the input.
8+
* required: If required is true, that means you have to input something, we can’t leave blank.
9+
* validate: Receives input as a parameter, when the input value is valid, it returns True.
10+
* cancelable: Whether the form can be canceled. Default is False.
11+
* PlaceHolder: This element is used only in the input_group function.
12+
* radio: Only a single can be selected.
13+
* select: You can also select multiple options by setting the “multiple” parameter to True.
14+
15+
## Working
16+
This form will take your username, name, password, email, and website link as input. Speaking of passwords, it will also check your password again to confirm whether it is correct or not. It will also validate your phone number, website link, and email address.
17+
18+
After that, you will get the radio button consisting of gender, and you will also get the comment section so that you can write your feedback. As you can see in the below image, first we have to pass the username, then we will pass the password, and then to check whether the password is correct or not, we will confirm it by reentering the new password. The name, phone number, and phone number will then be verified to see if they are valid.
19+
20+
When we pass the email, it will be verified using the re-module. Finally, pass the website link, so that we can access that site. And when we press the reset button, the whole content will refresh. When we press the submit button, it will be submitted and will show you the whole content.
21+
22+
## Output:
23+
<img width=50% src="../Registration Form Web App/Images/form.jpg">
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from pywebio.input import *
2+
from pywebio.output import *
3+
from pywebio.session import *
4+
import re
5+
6+
# For checking Email, whether Valid or not.
7+
regex = '^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,3}$'
8+
9+
# For checking Phone Number, whether Valid or
10+
# not.
11+
Pattern = re.compile("(0/91)?[6-9][0-9]{9}")
12+
13+
# For Checking URL, whether valid or not
14+
regex_1 = ("((http|https)://)(www.)?" +
15+
"[a-zA-Z0-9@:%._\\+~#?&//=]" +
16+
"{2,256}\\.[a-z]" +
17+
"{2,6}\\b([-a-zA-Z0-9@:%" +
18+
"._\\+~#?&//=]*)")
19+
Pattern_1 = re.compile(regex_1)
20+
21+
22+
def check_form(data):
23+
24+
# for checking Name
25+
if data['name'].isdigit():
26+
return ('name', 'Invalid name!')
27+
28+
# for checking UserName
29+
if data['username'].isdigit():
30+
return ('username', 'Invalid username!')
31+
32+
# for checking Age
33+
if data['age'] <= 0:
34+
return ('age', 'Invalid age!')
35+
36+
# for checking Email
37+
if not (re.search(regex, data['email'])):
38+
return ('email', 'Invalid email!')
39+
40+
# for checking Phone Number
41+
if not (Pattern.match(str(data['phone']))) or len(str(data['phone'])) != 10:
42+
return ('phone', 'Invalid phone!')
43+
44+
# for checking Website URL
45+
if not re.search(Pattern_1, data['website']):
46+
return ('website', 'Invalid URL!')
47+
48+
# for matching Passwords
49+
if data['pass'] != data['passes']:
50+
return ('passes', "Please make sure your passwords match")
51+
52+
53+
# Taking input from the user
54+
data = input_group("Fill out the form:", [
55+
input('Username', name='username', type=TEXT,
56+
required=True, PlaceHolder="@username"),
57+
58+
input('Password', name='pass', type=PASSWORD,
59+
required=True, PlaceHolder="Password"),
60+
61+
input('Confirm Password', name='passes', type=PASSWORD,
62+
required=True, PlaceHolder="Confirm Password"),
63+
64+
input('Name', name='name', type=TEXT, required=True,
65+
PlaceHolder="name"),
66+
67+
input('Phone', name='phone', type=NUMBER,
68+
required=True, PlaceHolder="12345"),
69+
70+
input('Email', name='email', type=TEXT,
71+
required=True, PlaceHolder="[email protected]"),
72+
73+
input('Age', name='age', type=NUMBER, required=True,
74+
PlaceHolder="age"),
75+
76+
input('Portfolio website', name='website', type=TEXT,
77+
required=True, PlaceHolder="www.XYZ.com")
78+
79+
], validate=check_form, cancelable=True)
80+
81+
# Create a radio button
82+
gender = radio("Gender", options=['Male', 'Female'], required=True)
83+
84+
# Create a skills markdown
85+
skills = select("Tech Stack", options=[
86+
'C Programming', 'Python', 'Web Development', 'Android Development'],
87+
required=True)
88+
89+
# Create a textarea
90+
text = textarea("Comments/Questions", rows=3,
91+
placeholder="Write something...", required=True)
92+
93+
# Create a checkbox
94+
agree = checkbox("Agreement", options=[
95+
'I agree to terms and conditions'], required=True)
96+
97+
# Display output using popup
98+
popup("Your Details",
99+
f"Username: @{data['username']}\nName: {data['name']}\
100+
\nPhone: {str(data['phone'])}\nEmail: {data['email']}\
101+
\nAge: {str(data['age'])}\nWebsite: {data['website']}\
102+
\nGender: {gender}\nSkill: {skills}\nComments: {text}",
103+
closable=True)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pip install pywebio

0 commit comments

Comments
 (0)