fsfi

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 3d7d9755ffce8930ea81ab3ce9497090781296ec
parent 10a599234f258d4be7dc9922623363d726443f29
Author: rsiddharth <s@ricketyspace.net>
Date:   Thu, 23 May 2019 19:01:40 -0400

static: Add contact/submit

Diffstat:
static/contact/submit/index.php | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
static/contact/submit/submit.html | 46++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/static/contact/submit/index.php b/static/contact/submit/index.php @@ -0,0 +1,62 @@ +<?php + +/** + * + * SPDX-License-Identifier: ISC + * + * Copyright © 2019 Free Software Foundation of India. + * + */ + +function to() { + return 's@cygnus.ricketyspace.net'; +} + +function email_valid($e) { + if (preg_match('/([\w.-]+)@([\w.-]+)/', $e)) { + return true; + } + return false; +} + +function send($n, $e, $m) { + $p = $n . ' <' . $e . '>'; + return mail(to(), + $p . ' sent a message to FSF India', + 'Per says:' . PHP_EOL . PHP_EOL . $m + ); +} + +function em_fw($t) { + return preg_replace('/^(\w+)( .+)/', '<strong>$1</strong>$2', $t); +} + +function post() { + $n = $_POST['name']; + $e = $_POST['email']; + $m = $_POST['msg']; + + $errors = []; + if (!email_valid($e)) { + $errors[] = em_fw('Email is invalid'); + } + if (empty($m)) { + $errors[] = em_fw('Message is required'); + } + + $sok = true; + if (empty($errors)) { + $sok = send($n, $e, $m); + } + if (!$sok) { + $errors[] = 'Unable to process your submission.'; + } + + return [ + 'ok' => empty($errors) && $sok, + 'errors' => $errors + ]; +} + +$result = post(); +include(__DIR__ . '/submit.html'); diff --git a/static/contact/submit/submit.html b/static/contact/submit/submit.html @@ -0,0 +1,46 @@ +<!--#include virtual="/includes/html-open.html"--> + +<!--#include virtual="/includes/header-open.html"--> +<title>Submit &mdash; Contact &mdash; Free Software Foundation India</title> +<!--#include virtual="/includes/header-close.html"--> + +<!--#include virtual="/includes/body-open.html"--> +<!--#include virtual="/includes/navbar.html"--> + +<div class="container main"> + <section class="section"> + <div class="content"> + <header> + <h1>Contact</h1> + </header> + + <div class="columns"> + <div class="column is-three-fifths"> + + <?php if ($result['ok']) { ?> + <p>We'll get back to you soon!</p> + <?php } else { ?> + <p>Oops! There were some issues:</p> + + <ul> + <?php foreach ($result['errors'] as $e) { ?> + <li><?=$e?></li> + <?php } ?> + </ul> + + <a class="button is-link" href="/contact">Try again</a> + <?php } ?> + + + </div> <!-- end column --> + </div> <!-- end columns --> + + </div> + </section> + +</div> + +<!--#include virtual="/includes/footer.html"--> +<!--#include virtual="/includes/js.html"--> +<!--#include virtual="/includes/body-close.html"--> +<!--#include virtual="/includes/html-close.html"-->