improve donate form - www.codemadness.org - www.codemadness.org saait content files
 (HTM) git clone git://git.codemadness.org/www.codemadness.org
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit b6e16ca379394d9f3ddb543824b028c2bd1e9881
 (DIR) parent 134683ca1f57d8487892de1bee1dcd5d38315ff6
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sat,  9 Nov 2024 19:27:53 +0100
       
       improve donate form
       
       Diffstat:
         M cgi-bin/donate/index.html           |      25 +++++++++++++++++++++----
         M cgi-bin/donate/main.c               |      20 ++++++++++++++++----
       
       2 files changed, 37 insertions(+), 8 deletions(-)
       ---
 (DIR) diff --git a/cgi-bin/donate/index.html b/cgi-bin/donate/index.html
       @@ -9,10 +9,21 @@ body {
                margin: 0 auto;
                width: 80ex;
        }
       -
        textarea, input {
                font-size: 140%;
        }
       +textarea, .text {
       +        width: 600px;
       +}
       +@media (prefers-color-scheme: dark) {
       +        :root {
       +                color-scheme: dark;
       +        }
       +        body {
       +                background-color: #000;
       +                color: #bdbdbd;
       +        }
       +}
        </style>
        
        <div class="form">
       @@ -21,11 +32,17 @@ textarea, input {
        <form method="get" action="/cgi-bin/donate">
        
        <p>
       +<label for="from"><b>From (optional):</b></label>
       +</p>
       +<input type="text" class="text" name="from" id="from" placeholder="From (optional)..." size="45" autofocus />
       +<br/>
       +
       +<p>
        <label for=""><b>Type of donation:</b></label>
        </p>
        
        <p>
       -<input type="radio" name="type" id="compliment" value="c" selected /> <label for="compliment">A nice compliment</label>
       +<input type="radio" name="type" id="compliment" value="c" checked /> <label for="compliment">A nice compliment</label>
        <input type="radio" name="type" id="hate" value="h" /> <label for="hate">Pure hatred</label>
        <input type="radio" name="type" id="joke" value="j" /> <label for="joke">A joke</label>
        <input type="radio" name="type" id="million" value="m" /> <label for="million">One million dollars</label>
       @@ -36,7 +53,7 @@ textarea, input {
        </p>
        
        <p>
       -        <textarea name="msg" cols="69" rows="3" id="msg" required></textarea>
       +        <textarea name="msg" cols="69" rows="5" id="msg" required></textarea>
        </p>
        
        <p>
       @@ -45,7 +62,7 @@ textarea, input {
        </p>
        
        <p>
       -        <input type="text" name="captcha" id="captcha" value="" placeholder="yes" required size="3" />
       +        <input type="text" name="captcha" id="captcha" value="" placeholder="yes" size="3" pattern="^yes$" required />
        </p>
        
        <p>
 (DIR) diff --git a/cgi-bin/donate/main.c b/cgi-bin/donate/main.c
       @@ -92,7 +92,7 @@ main(void)
                time_t now;
                FILE *fp;
                char filename[256];
       -        char _type[32], msg[4096], captcha[16];
       +        char _type[32], msg[4096], captcha[16], from[256];
                char *p, *query;
                int r, valid;
        
       @@ -116,6 +116,13 @@ main(void)
                if (!valid)
                        error("Captcha must be: yes\n");
        
       +        from[0] = '\0';
       +        if ((p = getparam(query, "from"))) {
       +                r = decodeparam(from, sizeof(from), p);
       +                if (r == -1)
       +                        from[0] = '\0';
       +        }
       +
                valid = 0;
                if ((p = getparam(query, "type"))) {
                        r = decodeparam(_type, sizeof(_type), p);
       @@ -147,15 +154,20 @@ main(void)
                if (!fp)
                        error("Cannot receive donation, thanks anyway.\n");
        
       +        if (from[0])
       +                fputs(from, fp);
       +        else
       +                fputs("Some person", fp);
       +
                switch (_type[0]) {
                case 'c':
       -                fputs("Some person sent a compliment:\n\n", fp);
       +                fputs(" sent a compliment:\n\n", fp);
                        break;
                case 'h':
       -                fputs("Some person sent pure hatred:\n\n", fp);
       +                fputs(" sent pure hatred:\n\n", fp);
                        break;
                case 'j':
       -                fputs("Some person sent a joke:\n\n", fp);
       +                fputs(" sent a joke:\n\n", fp);
                        break;
                }