We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53615
    • 5 Posts
    Hi modx professionals, i am new to modx and started my first project. Many things are quite easy but this makes me pulling my hair out:

    I have a textarea like
    <textarea name="message" id="message" cols="55" rows="7" value="[[!+fi.text]]">[[!+fi.text]]</textarea>

    in my form and I'm trying to fill it using a prehook like:
    <?php
    $hook->setValue('message','bla....');
    return true;

    but the textarea remains empty.
    I searched google and this forum without success.

    Isn't it possible to fill the textarea this way?

    What am i doing wrong?

    Thanks in advance
    Thomas
      • 17301
      • 932 Posts
      That should actually work. Can you post your call?
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 17301
        • 932 Posts
        Do you have anything in your error log also
          ■ email: [email protected] | ■ website: https://alienbuild.uk

          The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
          • 53615
          • 5 Posts
          Quote from: lkfranklin at Aug 09, 2017, 07:22 PM
          Do you have anything in your error log also

          Hi lkfranklin!
          Neither in the modx nor in apache2 logs.
          Tomorrow i post the complete code from my office.
            • 53615
            • 5 Posts
            Quote from: lkfranklin at Aug 09, 2017, 07:17 PM
            That should actually work. Can you post your call?
            This is my Form:
            [[!FormIt? &validate= `kennwort:required,
                                   text:required:stripTags,
                                   startWarn:regexp=^/[0-9]{2}[\/][0-9]{4}[zZ]/^,
                                   endWarn:regexp=^/[0-9]{2}[\/][0-9]{4}[zZ]/^,
                                   issued:regexp=^/[0-9]{2}[\/][0-9]{4}[zZ]/^,
                                   lfdNr:regexp=^/[0-9]{2}/^`
                       &clearFieldsOnSuccess= `0`
                       &preHooks= `loadWarnformParam`
                       &hooks=    `warnForm`
            ]]
            
            [[!+fi.validation_error_message:notempty=`<p>[[!+fi.validation_error_message]]</p>`]]
            
            <form action="[[~[[*id]]]]" method="post" class="form">
                <section>
                    <fieldset>
                        <legend>Inhalt:</legend>
                            <div>
                                <label for="kennwort"> Kennwort: <span class="error">[[!+fi.error.kennwort]]</span></label>
                                <input type="text" name="kennwort" id="kennwort" placeholder="Gewitter, Wind, Starkniederschlag etc." value="[[!+fi.kennwort]]">
                            </div>
                            <div id="warntext>
                                <label for="text"> Warntext: <span class="error">[[!+fi.error.text]]</span></label>
                                <textarea name="text" id="text" cols="50" rows="3" placeholder="Bitte Warntext eingeben..." value="[[!+fi.text]]" />[[fi.text]]</textarea>
                            </div>
                            <div>
                                <label for="startWarn"> gültig von: <span class="error">[[!+fi.error.startWarn]]</span></label>
                                <input type="text" name="startWarn" id="startWarn" placeholder="15/0800Z" value="[[!+fi.startWarn]]">
                            </div>
                            <div>
                                <label for="endWarn"> bis: <span class="error">[[!+fi.error.endWarn]]</span></label>
                                <input type="text" name="endWarn" id="endWarn" placeholder="15/2200Z" value="[[!+fi.endWarn]]">
                            </div>
                            <div>
                                <label for="issued"> herausgegeben am: <span class="error">[[!+fi.error.endWarn]]</span></label>
                                <input type="text" name="issued" id="issued" value="[[!+fi.issued]]">
                            </div>
                            <div>
                                <label for="lfdNr"> ETMN Nr: <span class="error">[[!+fi.error.lfdNr]]</span></label>
                                <input type="text" name="lfdNr" id="lfdNr" placeholder="01" value="[[!+fi.lfdNr]]">
                            </div>
                            <div>
                                <label for="chngcncl"> Aufhebung/Änderung: <span class="error">[[!+fi.error.chngcncl]]</span></label>
                                <input type="text" name="chngcncl" id="chngcncl" placeholder="Aufhebung Nr.XX/Änderung Nr. XX" value="[[!+fi.chngcncl]]">
                            </div>
                    </fieldset>
                    <div class="form-buttons">
                        <input type="submit" value="Warnung erstellen">
                    </div>
                </section>
            </form>


            this is the prehook
            <?php
            $fp = fopen("images/geomops1/Warnung_nicht_loeschen.txt","r");
            $i = 0;
            if($fp){
                while(!feof($fp)){
                   $zeile[$i] = fgets($fp);
                   $i++;
                }
                fclose($fp);
                $hook->setValue('kennwort', substr($zeile[0],3));
                $hook->setValue('text', substr($zeile[1], 3));
                $hook->setValue('startWarn', substr($zeile[2], 15, 8));
                $hook->setValue('endWarn', substr($zeile[2], 28, 8));
                if (strlen($zeile[4]) !== 0) {
                    $hook->setValue('issued', substr($zeile[4], 14, 8));
                } else {
                    $timestamp = time();
                    $datum = date("d/Hi", $timestamp) . "Z";
                    $hook->setValue('issued',$datum);
                }
                $hook->setValue('lfdNr', substr($zeile[5], 12, 2));
            }  
            else {
                $modx->log(xPDO::LOG_LEVEL_ERROR,'unable to open $Bulletin');
                print "Datei $Bulletin nicht gefunden<br>";
                $timestamp = time();
                $datum = date("d/Hi", $timestamp) . "Z";
                $hook->setValue('issued',$datum);
            }
            return true;


            and this is the hook processing the form and writing the *txt file
            <?php
            $hook=$scriptProperties['hook'];
            $kennwort = $hook->getValue('kennwort');
            $warntext = $hook->getValue('text');
            $startWarn = $hook->getValue('startWarn');
            if (stristr($startWarn, "Z") === FALSE) {
                $startWarn = $startWarn . "Z";
            }
            $endWarn = $hook->getValue('endWarn');
            if (stristr($endWarn, "Z") === FALSE) {
                $endWarn = $endWarn . "Z";
            }
            $issued = $hook->getValue('issued');
            if (stristr($issued, "Z") === FALSE) {
                $issued = $issued . "Z";
            }
            $lfdNr = $hook->getValue('lfdNr');
            $chngcncl = $hook->getValue('chngcncl');
            if (strlen($chngcncl) > 0) {
                $chngcncl = "\r\n" . "7. " . $chngcncl;
            } else {
                $chngcncl = "";
            }
            $sign = $hook->getValue('sign');
            $check = "cancel";
            if (strcasecmp($warntext, "cancel") !== 0) {
                $text = "1. " . $kennwort . "\r\n" . "2. " . $warntext . "\r\n" . "3. Gültig von " . $startWarn . " bis " . $endWarn . "\r\n" . "4. ETMN und Umgebung " . "\r\n" . "5. ausgegeben " . $issued . "\r\n" . "6. ETMN Nr. " . $lfdNr . $chngcncl;
            } else {
                $text="";
            }
            $myfile = fopen("images/geomops1/Warnung_nicht_loeschen.txt", "w") or $modx->log(xPDO::LOG_LEVEL_ERROR, 'unable to write warn message');
            
            fwrite($myfile, $text);
            fclose($myfile);
            
            return true;  //<-- if you omit this or return false, your form won't validate


            Hope this helps

            Sincerely Thomas
              • 53615
              • 5 Posts
              I tried my code on another machine and it is doing well. seems to me, that my modx installation is broken in some way.
                • 53615
                • 5 Posts
                it works!
                the <div></div> around the textarea had prevented the setValue process.
                  • 17301
                  • 932 Posts
                  Ah yeah missing quote, I see it now. Glad you got it working.
                    ■ email: [email protected] | ■ website: https://alienbuild.uk

                    The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.