[gnome-web-www] Add simple field validation and keep the values if it went wrong



commit d0da65fa97ec2038a98440ab3d0479be357bf0f2
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Wed Jun 5 13:17:59 2019 +0200

    Add simple field validation and keep the values if it went wrong

 theme/page-apply.php | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)
---
diff --git a/theme/page-apply.php b/theme/page-apply.php
index b72cf5f..82b4e67 100644
--- a/theme/page-apply.php
+++ b/theme/page-apply.php
@@ -1,5 +1,7 @@
 <?php
 
+$full_name = $email = $ssh_key = "";
+$summary = $references = $gnome_username = "";
 
 if (array_key_exists('submit', $_POST)) {
 
@@ -10,19 +12,20 @@ if (array_key_exists('submit', $_POST)) {
     $full_name = trim(stripslashes($_POST['full_name']));
     $email = trim(stripslashes($_POST['email']));
     $obfuscated_email = str_replace("@", " AT ", $email);
+    $ssh_key = trim($_POST['sshkey']);
     $not_spam = $_POST['not_spam'];
     
     if ($not_spam != 'not spam') {
         $errors = true;
     }
-    
-    $summary = trim(stripslashes($_POST['summary']));   
+
+    $summary = trim(stripslashes($_POST['summary']));
     $gnome_mail_alias = trim(stripslashes($_POST['gnome_mail_alias']));
     $gnome_username= trim(stripslashes($_POST['gnome_username']));
     $gnome_jabber = trim(stripslashes($_POST['gnome_jabber']));
     $references = trim(stripslashes($_POST['references']));
     
-    if (empty($full_name) || empty($email) || empty($summary) || ($gnome_mail_alias == 'on' && 
empty($gnome_username))) {
+    if (empty($full_name) || empty($email) || empty($summary) || empty($ssh_key) || ($gnome_mail_alias == 
'on' && empty($gnome_username))) {
         $errors = true;
     }
     
@@ -33,6 +36,7 @@ if (array_key_exists('submit', $_POST)) {
         
         "Full Name: " . $full_name . "\n".
         "Email:     " . $obfuscated_email . "\n\n" .
+        "SSH key:     " . $ssh_key . "\n\n" .
 
         "Benefits\n" .
         "Mail alias: " . ($gnome_mail_alias == 'on' ? "Yes" : "No") . "\n".
@@ -92,6 +96,8 @@ if (array_key_exists('submit', $_POST)) {
 
 <h2 style="text-align: center;">Application Form</h2>
 
+<?php echo "Some of required fields in the form are missing. Please fill them and submit again."; ?>
+
 <form action="" method="post" id="application_form">
 
   <script>
@@ -111,12 +117,17 @@ if (array_key_exists('submit', $_POST)) {
 
 <div class="item">
     <label for="full_name">Full Name</label>
-    <input name="full_name" id="full_name" type="text">
+    <input name="full_name" id="full_name" type="text" value="<?php echo htmlspecialchars($full_name);?>" >
 </div>
 
 <div class="item">
     <label for="email">E-mail Address</label>
-    <input name="email" id="email" type="text">
+    <input name="email" id="email" type="text" value="<?php echo htmlspecialchars($email);?>">
+</div>
+
+<div class="item">
+    <label for="email">SSH public key</label>
+    <input name="sshkey" id="sshkey" type="text" value="<?php echo htmlspecialchars($sshkey);?>">
 </div>
 
 <h3>Benefits</h3>
@@ -131,16 +142,16 @@ if (array_key_exists('submit', $_POST)) {
     When choosing a @gnome.org alias, please, check our 
     <a href="https://wiki.gnome.org/AccountNamePolicy";>account name policy</a>. 
     Your @gnome alias will point to the e-mail you specified above as your permanent e-mail address.  If you 
do
-    own a GNOME Git Account, make sure the choosen username is the one you use for your read, write access 
to git.gnome.org.
+    own a GNOME GitLab Account, make sure the choosen username is the one you use to access your account 
there.
 </p>                        
 
 <div class="item benefits">
-    <input name="gnome_mail_alias" id="gnome_mail_alias" type="checkbox" onClick="toggleBenefitsFields()" /> 
@gnome.org mail alias
-    <input name="gnome_username" id="gnome_username" type="text" placeholder="What do you want your username 
to be?" disabled />
+    <input name="gnome_mail_alias" id="gnome_mail_alias" type="checkbox" onClick="toggleBenefitsFields()" 
value="<?php echo $gnome_mail_alias ;?>" /> @gnome.org mail alias
+    <input name="gnome_username" id="gnome_username" type="text" placeholder="What do you want your username 
to be?" value="<?php echo htmlspecialchars($gnome_username);?>" disabled />
 </div>
 
 <div class="item benefits">
-    <input name="gnome_jabber" id="gnome_jabber" type="checkbox" disabled /> 
+    <input name="gnome_jabber" id="gnome_jabber" type="checkbox" disabled value="<?php echo $gnome_jabber 
;?>" />
     <span name="jabber_label" id="jabber_label" class="disabled-checkbox">Jabber account <em>(only if you 
adopt a @gnome.org mail alias)</em></span>
 </div>
 
@@ -149,10 +160,10 @@ if (array_key_exists('submit', $_POST)) {
 <div class="item">
     <p>
         Please list references to your contributions, i.e. Gitlab (commits, tasks), Mailing Lists or 
deprecated Bugzilla.
-        Processing will be much quicker if you provide links. Please tell us whether you were an existing 
+        Processing will be much quicker if you provide links. Please tell us whether you were an existing
         Foundation member or have done something relevant for the GNOME Foundation in the past.
     </p>
-    <textarea name="summary"></textarea>
+    <textarea name="summary">"<?php echo htmlspecialchars($summary);?>"</textarea>
 </div>
 
 <h3>References</h3>
@@ -160,10 +171,10 @@ if (array_key_exists('submit', $_POST)) {
 <div class="item">
     <p>
         It helps us processing your application faster if you provide names and email addresses of two or
-        more current <a href="https://www.gnome.org/foundation/membership";>Foundation members</a> who could 
+        more current <a href="https://www.gnome.org/foundation/membership";>Foundation members</a> who could
         vouch for you and your contributions.
     </p>
-    <textarea name="references"></textarea>
+    <textarea name="references"><?php echo htmlspecialchars($references);?></textarea>
 </div>
 
 <hr />


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]