Copied to clipboard

Flag this post as spam?

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


  • kodermax 39 posts 59 karma points
    Jun 15, 2015 @ 15:08
    kodermax
    0

    Contact Form Save to DB

    How can i save requests from form to DB for this http://carlosmartinezt.com/2014/06/umbraco-7-and-mvc-contact-form/ ?

  • Ifrahim Rasool 28 posts 84 karma points
    Jun 15, 2015 @ 15:24
    Ifrahim Rasool
    0

    After sending email, write code to save data to database. Here is an example, paste following after SendMail() function.

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString); con.Open(); SqlDataAdapter sda = new SqlDataAdapter("SaveEnquiry", con); sda.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure; sda.SelectCommand.Parameters.Add(new SqlParameter("@Name", Model.FullName)); sda.SelectCommand.Parameters.Add(new SqlParameter("@Email", Model.Email)); sda.SelectCommand.Parameters.Add(new SqlParameter("@Telephone", Model.Telephone)); sda.SelectCommand.Parameters.Add(new SqlParameter("@Comments", Model.Comments)); sda.SelectCommand.ExecuteNonQuery(); sda.Dispose(); con.Close();

    You will need to write Stored Procedure in SQL database to handle this transaction. Or you can also write inline INSERT statement.

  • Ifrahim Rasool 28 posts 84 karma points
    Jun 15, 2015 @ 15:33
    Ifrahim Rasool
    0

    Here is cleaner version of above code:

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString); 
    con.Open(); 
    SqlDataAdapter sda = new SqlDataAdapter("SaveEnquiry", con); 
    sda.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure; 
    sda.SelectCommand.Parameters.Add(new SqlParameter("@Name", Model.FullName)); 
    sda.SelectCommand.Parameters.Add(new SqlParameter("@Email", Model.Email)); 
    sda.SelectCommand.Parameters.Add(new SqlParameter("@Telephone", Model.Telephone)); 
    sda.SelectCommand.Parameters.Add(new SqlParameter("@Comments", Model.Comments)); 
    sda.SelectCommand.ExecuteNonQuery(); 
    sda.Dispose(); 
    con.Close();
    
  • kodermax 39 posts 59 karma points
    Jun 15, 2015 @ 15:45
    kodermax
    0

    But, how can I use umbraco admin interface for reading this entries?

  • Ifrahim Rasool 28 posts 84 karma points
    Jun 15, 2015 @ 15:47
    Ifrahim Rasool
    0

    You have a couple of options:

    1. Create a new Custom Section in Umbraco to display all enquiries
    2. Create a password protected content node to display all enquiries
    3. Create a scheduled SQL job to send enquiries report to administrator
  • kodermax 39 posts 59 karma points
    Jun 15, 2015 @ 15:54
    kodermax
    0

    This is not easy process, may be. Umbraco has ready api for this ?

Please Sign in or register to post replies

Write your reply to:

Draft