Playing with Razor in Umbraco : an old skool contact form

Standard

This is clearly not the way a state of the art contact form should be made in Umbraco. But to learn and have fun with the new Razor possibilities I created a very basic contact form:

Edit : please also see this newer article about how to make a simple contact form with better code structure.

Here’s the complete code

@if (!IsPost)
{
    <form method="POST">
    Tell us what you think:<br/><textarea name="msg" rows="3" cols="40"></textarea><br/>
    Your name:<br/><input type="text" name="name"/><br/>
    <input type="submit" value="Send your message to us"/>
    </form>
}
else
{
    var message = Request["msg"];
    var name = Request["name"];
    umbraco.library.SendMail("from@mysite.com","to@mysite.com","Message from " + name,message,false);
    <strong>Thank you for your message @name:</strong><br/>@message
}
About these ads

4 thoughts on “Playing with Razor in Umbraco : an old skool contact form

  1. Petr

    Adding functions was possible long time ago using script runat server like this (I use it a lot):

    <script runat=”server”>
    public int GetLevel() {
    string path = umbraco.presentation.nodeFactory.Node.GetCurrent().Path;
    int count = 0;
    foreach (char c in path)
    if (c == ‘,’) count++;
    return count;
    }
    </script>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s