Onlinebase

Mura CMS - Autopopulating forms with Mura data

For a new Mura CMS website that requires users to log in before viewing content, I had created a simple contact form where the data is collected by Mura upon submission. This was all done with some simple HTML, pasted into the FORMS module in Mura. Simple validation was done with data-tags in the input-fields and the contact form was ready to go. But wait, why should the user re-enter all user data already present in the session object. The user has logged in, so we know who he/she is. Looking thru the Mura forums didn't really get me anywhere, so I tried to add a simple [MURA] tag to the form. In it I placed the string "session.mura.email" and lo-and-behold in my contact form I now had the users email address displayed. Then I went all out and created the contact form below:

<form class="form-horizontal" method="post" name="contact">
    <p>[mura]dspInclude('display_objects/dsp_form_protect.cfm')[/mura]</p>
    <fieldset><legend>Your Information</legend>
        <div class="form-group required"><label class="control-label col-xs-12 col-sm-3" for="txtNameFirst">First Name</label>
            <div class="col-xs-12 col-sm-9"><input class="form-control" id="txtNameFirst" name="txtNameFirst" readonly="readonly" required="true" type="text" value="[mura]HTMLEditFormat($.currentUser('fname'))[/mura]" /></div>
        </div>
        <div class="form-group required"><label class="control-label col-xs-12 col-sm-3" for="txtNameLast">Last Name</label>
            <div class="col-xs-12 col-sm-9"><input class="form-control" id="txtNameLast" name="txtNameLast" readonly="readonly" required="true" type="text" value="[mura]HTMLEditFormat($.currentUser('lname'))[/mura]" /></div>
        </div>
        <div class="form-group required"><label class="control-label col-xs-12 col-sm-3" for="txtEmail">Email Address</label>
            <div class="col-xs-12 col-sm-9"><input class="form-control" data-message="Please provide a correct email address" data-required="true" data-validate="email" id="txtEmail" name="txtEmail" readonly="readonly" required="true" type="text" value="[mura]HTMLEditFormat($.currentUser('email'))[/mura]" /></div>
        </div>
    </fieldset>
    <fieldset><legend>Your Message</legend>
        <div class="form-group required"><label class="control-label col-xs-12 col-sm-3" for="txtMessage">Message</label>
            <div class="col-xs-12 col-sm-9"><textarea class="form-control" id="txtMessage" name="txtMessage" placeholder="Message" required="true"></textarea></div>
        </div>
    </fieldset>
    <div class="form-group">
        <div class="col-xs-8 col-sm-offset-3 col-sm-6">
            <p class="required">Required Fields</p>
        </div>
        <div class="col-xs-4 col-sm-3 text-right"><button class="btn btn-md btn-success" type="submit">Submit</button></div>
    </div>
</form>

[MURA]-bracket notation to the rescue! Thanx Mura!

PS: Here's the link to a Google Groups discussion concerning the above: https://groups.google.com/forum/#!topic/mura-cms-developers/CUuso3By3mA

Geplaatst op 14 augustus 2014 om 18:05 u.

Alles in 'Ontwikkeling'

10 bericht(en)