Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • jaco steketee 30 posts 187 karma points
    Mar 29, 2021 @ 11:31
    jaco steketee
    0

    Saving Form Content to Database

    Hi, i hope someone can help me with this. Ive created a form in umbraco and its used for emailing reservations. This is working fine. But now i want to save each reservation into the database. I can't figure out how im supposed to do that.

    Greets, Jaco

  • Brendan Rice 538 posts 1102 karma points
    Mar 29, 2021 @ 11:46
    Brendan Rice
    0

    Here's the official docs jaco:

    https://our.umbraco.com/documentation/getting-started/Code/Creating-Forms/

    You'd do the DB work in the controller.

    Here's one way to create the custom table:

    https://our.umbraco.com/documentation/Extending/Database/

    Umbraco uses NPoco (ORM) and a lot of developers like using it for CRUD (Create, Retrieve, Udate and Delete) code:

    https://github.com/schotime/NPoco

    It should be available within Umbraco.

  • jaco steketee 30 posts 187 karma points
    Mar 29, 2021 @ 13:06
    jaco steketee
    0

    Thank you very much Brendan:) i've managed to create a table in the database. But how do i insert a record, or get data into a view using a select statement?

  • Brendan Rice 538 posts 1102 karma points
    Mar 29, 2021 @ 14:06
    Brendan Rice
    0

    Look at the links I shared above.

    The steps should be:

    On save data

    1. The form will post a ViewModel to a controller action
    2. In the action write the code to put the data (ViewModel) into the DB table (see NPOCO documentation)

    On retrieve data

    1. In the controller (look at the docs for surface controllers) you'll have an action method to retrieve the data from the DB and populate a model

    2. Model gets returned to the view

    3. Profit

    If you are new to Umbraco Paul Seal has a brilliant YouTube channel that will help you get up to speed:

    https://codeshare.co.uk/videos/

Please Sign in or register to post replies

Write your reply to:

Draft