1

This is probably easy to do but I've spent hours searching Composite C1 knowledge base and google but nothing.

I simply want to create an html form, then when the user submits it, be able to process the form fields in C#. I don't mind if this uses web forms, MVC or some other mechanism.

I have got inline functions working but it's not clear how to pass in the form fields.

thx.

niico
  • 11,206
  • 23
  • 78
  • 161

2 Answers2

1

I am a composite c1 noob myself, but one thing that I did and it seemed fairly straight forward was to understand how the contact form that comes with the Venus starter site works.

The Venus template contact form is driven by the function found in Functions > Razor > Composite > Form > Contact Form. You can edit that function and you can see how it's implemented. Inside that function you have access to the form data and you can do pretty much whatever you want with it, since it's C# and Razor.

Additionally, you can create a custom Global Datatype and optionally an associated Page Datafolder to save your data, or have access to it outside the form function. These will have to be bound to the form function.

You can get the data submitted from the form using the automatically generated functions (should be located under Functions > All Functions > YourNamespace > YourDatatype). I've used the GetMyDataTypeXml function for what I was needing and it worked without issues.

You can read more about data functions here: http://docs.composite.net/Data/Data-Centric-Functions Some examples of using the GetMyDatatypeXml function can be found here: http://docs.composite.net/Data/Data-Centric-Functions/Getting-Data-as-XML

HTH!

alex.g
  • 187
  • 1
  • 7
  • I think the 'form builder' is a paid plug-in - that has a 1 month demo in the sample site. Do you know if the Contact Form uses that paid plugin? (it appears to). – niico May 05 '16 at 23:57
  • There is also no "Functions > Razor > Composite > Form > Contact Form". The closest is "Functions > Razor Functions > Composite > Forms > Form Builder > Form.cshtml" - is that what you were talking about or is something missing from my venus? – niico May 06 '16 at 00:17
  • I'm not talking about Functions > Razor Functions > Composite > Forms > Form Builder > Form.cshtml". I have that one, but I also have "Functions > Razor > Composite > Form > Contact Form" and afaik that came with the Venus template. Eitherway, the plugin recommended by @Pauli-Østerø seems to be the correct tool for the job, I was not aware of that one. – alex.g May 06 '16 at 11:37
  • "Functions > Razor > Composite", I don't have. Do you mean "Functions > Razor Functions..." I have that but not "Contact Form". – niico May 06 '16 at 12:52
  • I have used Form Submit Handler - but it has various limitations, doesn't work with different SMTP details I've used, and it would be very useful to be able to run standard C# code... – niico May 06 '16 at 12:53
1

The Form Submit Handler is a simple addon that accepts all the values posted to the page and saves it to files on the server.

It can be a good starting point to see how to work with Forms withing C1. The code for it is available on GitHub.

Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48
  • Thanks. I was using this but for some reason it doesn't work when I plug smtp details into the web.config (details which do work in code). Also form validation is hard & I would also like to know how to just run regular C# code... – niico May 06 '16 at 12:51
  • The addon does no fancy things when sending the email, so my first thought is that your error must be elsewhere https://github.com/Orckestra/C1-Packages/blob/master/Composite.Forms.FormSubmitHandler/Composite.Forms.FormSubmitHandler/Handler.cs#L130 If you want a full-fledged Form Builder with validation and all, then take a look at this project https://github.com/burningice2866/CompositeC1Contrib.FormBuilder – Pauli Østerø May 09 '16 at 09:25
  • Thanks - turns out Gmail has really locked down email sending via SMTP now - that may have been part of the issue. I'll check to that project thx - is that the same as the paid Form Builder add on - or is it something different? – niico May 09 '16 at 11:36
  • @niico there is there Dynamic addon which is kinda like the paid Form Builder fra Composite, but i mainly ise the POCO addon which is a code-first approach where all forms and validation rules are defined i C# code. – Pauli Østerø May 09 '16 at 13:38