Jump to content

Recommended Posts

Hi,

Started this topic on this thread but moved to here as it is quite different.

I am looking for some help to code my own templates to achieve the following using the API and database:

1. Email from form submission.

2. Enter form data into database.

3. Validate users input in each form field.

34. Use db data to create reports.

 

I currently use my own html forms in the templates and to date have only directly emailed from the submission. I am working on a project to convert a pdf application form into an online <form>.

Input types include: text; textarea (TinyMCE); radio; jQuery UI datepicker (value = "datepicker id"); email; select (options from pages); hidden & submit.

There's probably more questions but that wil do to start.

Edited by NooseLadder
Link to comment
Share on other sites

Now we are talking :)

Please clarify:

#2: Do you want to save this as PW pages or in custom db fields in your PW database?

#3. What sort of reports do you want to create? PDF, Excel, etc? (this should be #4 actually?)

Edited:

Edited by kongondo
Link to comment
Share on other sites

This classic thread started by Matthew will get your started with #2 and #3 (validation = sanitization + correct input)

http://processwire.com/talk/topic/3105-create-pages-with-file-upload-field-via-api/

PW $input variable: http://processwire.com/api/variables/input/

Great form examples in Soma's Gist: https://gist.github.com/somatonic

Edited by kongondo
  • Like 4
Link to comment
Share on other sites

Now we are talking :)

Please clarify:

#2: Do you want to save this as PW pages or in custom db fields in your PW database?

#3. What sort of reports do you want to create? PDF, Excel, etc? (this should be #4 actually?)

Edited:

Thanks for your reply.

#2 Probably best as db fields in PW database.

#4 I would like to create the report as a page in the admin with the option to view as html or export as Excel or PDF.

@kongondo: Thanks for the other links I will digest accordingly.

Link to comment
Share on other sites

#2 Probably best as db fields in PW database.

#4 I would like to create the report as a page in the admin with the option to view as html or export as Excel or PDF.

If the report will end up being a page in the admin you might as well do this in #2 by creating a page then. Since a page's data is also stored in the db, why have a db entry (page) for the report (#4) as well as another db entry for the form (#2)? Anyway, I don't know your exact needs.

As for exporting to PDF, there is a module for that. Check the modules directory.

Have a go at the code in the links I posted above then we can take it from there if you get stuck. Bottom line is you will need to use:

  • $input->post (assuming you are not creating a multi-dimensional array; in such a case, you would use PHP's $_POST) to handle the form data
  • $sanitizer - to sanitize your data. You can also (additionally) use client side validation just to make sure emails are formatted correctly, etc.
  • new Page to create and save new pages based off your form input data
  • PW db class if you want to save your form data to custom db tables. You can also use PHP msqli or PDO. If using custom tables, you will need to create this either using PHP or directly in phpMyAdmin or similar
  • An email class to send your emails

I might have forgotten something...

  • Like 1
Link to comment
Share on other sites

If the report will end up being a page in the admin you might as well do this in #2 by creating a page then. Since a page's data is also stored in the db, why have a db entry (page) for the report (#4) as well as another db entry for the form (#2)? Anyway, I don't know your exact needs.

I have only just started looking at this, but to answer your question:

The form will put all the variables into the db. The form takes details of a course booking.So each form submit needs to be entered into the db. If the form has the following fields:

Firstname, Lastname, Address Line 1, Address Line 2, Postcode, Gender, Date of birth, Hidden field to calculate age from dob, email, telephone, Course start date, end date, the course, comments.

Each submission needs to store these fields in the db.

I would like to create reports based on a selection of these fields. There will also be admin only pages to create the courses/dates etc that are displayed on the course html pages. And to capture who has paid, who hasn't, parental consent given. So the reports will be using fields from the form input as well as admin pages and possibly calculated variables as well. I hope that clarifies my needs a bit better?

Examples of required reports might be but not limited to:

1. List of all clients with contact details.

2. Who is booked onto what course.

3. Outstanding payments.

You mentioned above 

  • new Page to create and save new pages based off your form input data

Is it best to create a new page for every form submission or just enter the data into the db?

I will take a look at the links and advice you gave above. Thanks.

Edited by NooseLadder
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...