I've just posted a free addon for designers/developers that need a totally customizable contact form:
https://github.com/jordanlev/c5_custom_contact_form
Some of you may already be aware of that addon (it's been up on github for a long time), but I recently rewrote the whole thing to be WAY easier to configure (there's only 2 files you need to tweak now), added some handy features (automatic dashboard reports with CSV download, spam honeypot fields, notification email "reply-to" for the form submitter), and significantly cleaned up the code internally (which makes it easier to customize if you need to add your own form processing logic).
This thing started out as my answer to the ill-conceived "External Form" block that is included in the core system (which I always uninstall immediately when creating new C5 sites for a myriad of reasons), but has accumulated a lot of handy features along the way. So while it's configured out-of-the-box for contact forms, I also think it's a good starting point for all sorts of other custom forms (as long as you don't need to give users the ability to configure the form themselves).
Comments
For HTML emails, you can declare a $bodyHTML variable and set whatever content you want. Note that it is probably a good idea to keep the plaintext $body as well so there is a fallback for people who don't have HTML emails enabled.
Do I need to go through EVERY file in the package and change every occurrence of those 4 listed strings? Also do I need to change up strings that extend further for example: CustomContactFormPackage -> CustomContactForm2Package ?
Otherwise the single one was breeze to install and use but this seems to a lot more complicated than I thought initially. But I would really like to use your implementation since the first one was so easy to work out.
https://github.com/jordanlev/c5_custom_contact_form#optional-steps
...item #4 lists all of the file names that need to be changed, and all of the strings that need to be replaced in code. I usually change the filenames myself, but use my text editor to find/replace all occurrences of the strings in code. If you aren't familiar with how to do a global "find and replace" for all of the files in a folder, it is a very handy technique that I highly recommend learning about as it will serve you well across all kinds of projects (Concrete5 and otherwise).
Best of luck!
-Jordan
You've been a great help, thanks a lot for helping out!
Was looking just for something like this addon, the external form addon is too complicated for me :)
I tried this:
echo $form->select('country', null);
but get the following error:
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\espinerdemo\concrete\core\helpers\form.php on line 341
Any help appreciated.
Ian
Ian
The way the C5 form helper works, you need to pass an array of options as the 2nd argument. You need to do something like this instead:
echo $form->select('country', array('US' => 'United States', 'UK' => 'United Kingdom', [...]);
There's an example of using the dropdown in this way in the code itself:
https://github.com/jordanlev/c5_custom_contact_form/blob/0ad7e83209856f98bef7892a938f1c56118af061/packages/custom_contact_form/blocks/custom_contact_form/view_form_fields/my_first_form.php#L37-L43
Hope that helps!
-Jordan
I do have another question though if I may. I have set up a order form using this block and its currently placed on my profile page so when a client logs in they get the form and order some materials. It all works great and saves the data and creates report as it shoudl in the dashbord.
What I would like to do is show on the profile page next to the form the recent order byt that user. Could you point me to a section of code or a page that could help me along my way in getting what I want? Basically like the dashboard report but on the profile page when they login?
(I have saved the userid as part of the form save to help target each submission)
The contact form does not store the user id, so you'd need to make some non-trivial changes to the code (it would require some decent php/programming knowledge -- if you are comfortable with the code then it's certainly doable, but if you're not very experienced with php then it's probably not feasible).
Specifically: you need to alter the database table structure to add the user id field to the custom_contact_form_submissions table, then the model class would need to grab the user id and save that to the db when a submission is saved, and then you'd need a query to retrieve submissions from a particular user id and output them to your profile page. Look at the "getSubmissionsForDashboard" function in the model class to see how to JOIN the fields to the submission records (and how you can convert the normalized query results into a PHP array where the fields are grouped by their submission).
-Jordan
I gathared this from the "getSubmissionsForDashboard" function and a forumn you posted too here: http://www.concrete5.org/community/forums/chat/need-to-add-some-php-to-talk-to-a-mysql-db/
I have placed a 9 after "WHERE s.form_key = 9" just to try and get something to show before I fiddle to get it based on user_id but I dont know what to put here: $vals = array(??????);
You have been very helpful so far but if you could help me again that would be great.
Ian
Thanks
I'm sorry but the code you pasted and the questions you are asking require more time and details to address than I am able to provide here in the comments. I wish this were an easier task to accomplish, but unfortunately it's not very straightforward.
If you'd like more detailed assistance with this job, you can get in touch with my company about consulting work. I imagine that achieving what you're asking would probably be in the $250-$500 (USD) range (if I'm understanding the requirements fully).
If you'd like to get in touch about that, please email us at: hello@webconcentrate.com
Best,
Jordan
Mail Exception Occurred. Unable to send mail: Unable to send mail. mail(): SMTP server response: 550.
Is this an eassily resolved issue that you can point me towards? or more of a concrete5 issue?
Ian
Mail errors can be caused by many different factors. It is generally not a problem with Concrete5 specifically, but if you search through the C5 forums you will find a lot of people with similar issues. For example:
http://www.concrete5.org/community/forums/installation/external-smtp-server/
http://www.concrete5.org/community/forums/customizing_c5/form-not-sending-email-see-logs
...hopefully you can find a workable solution there. Best of luck!
-Jordan
Great work as always :-) I use your custom form on a number of sites, but recently I've noticed we're getting a fair bit of contact form spam via some of our c5 sites - just wondering whether the honeypot is no longer effective?
Most of the spam that comes through is highly automated, and contains links in the message body - is there an easy way to set your templates to return as invalid if the body contains links perhaps?
Cheers,
J
Thanks, glad the addon is helping you. We notice that spam ebbs and flows, and it differs from site to site (no idea why though). In my experience, when a simple honeypot isn't working well enough, the best alternative is to use akismet. I think it's only $5 per month, and it's relatively easy to plug into.
If I have some extra time the next time I build a site with this addon, I'll see if I can integrate that into the functionality... but I unfortunately can't give you a specific timeline on that, so if you're in a rush I'd say you should look into doing that yourself. Or if you would like to hire my company to do this for you we'd be happy to give you an estimate -- just email us at hello@webconcentrate.com
Cheers,
Jordan
@Andrew, this addon uses C5's "mail helper", which in turn uses whatever you set via Dashboard > System & Settings > Email > SMTP Method
The best thing you could do is fork the project in github and then create a branch with your changes. But that is on the more complex end of git things so if you're not super familiar with how it all works, you can just email me a zip file and when I get a chance I'll take a look at it. You can email me at jordan@concrete5tricks.com
Thanks!
Quick question...what would be the best way to get a date picker into one of these forms? Something that is going to work with formatting correctly in the notification email.
If you just need a date picker (no time fields), it's pretty easy.
You can use `echo Loader::helper('form/date_time')->date('my_date_field');` to make the input field appear. And to get the datepicker CSS/JavaScript, append the following to the `on_page_view() {}` function in `blocks/custom_contact_form/controller.php`.
`
$this->addHeaderItem(Loader::helper('html')->css("jquery.ui.css"));
$this->addHeaderItem(Loader::helper('html')->javascript("jquery.ui.js"));
`
The notification email will have the date formatted in a "m/d/yyyy" format (the same format the datepicker adds it to the input field).
If you need time fields with C5's date picker, you'll also need to incorporate the `translate()` function when the form is processed. That function is described here: https://www.concrete5.org/documentation/developers/5.6/forms/concrete5-widgets/. That starts getting a little more complicated though. If you need help with that, I can ask Jordan to explain when he returns.
Another (and possibly more simple) option for adding time fields would be to create separate "select" fields of your own in the form. What's nice about making your own fields is you would avoid needing to edit other files within this addon.
Hopefully that helps. Let us know if we can explain further.
I'm not yet using 5.7 on client projects yet, and I'm swamped with other work so unfortunately I don't have the opportunity to do any 5.7-related things right away. However it will need to happen at some point, so I'm hoping to start using 5.7 for new sites some time this summer... and of course I'll need all these things like contact form and designer content working. So for now it's just a "coming some time soonish but I don't know exactly when".
Usually it just works out-of-the-box, so if it's not working for you it's probably due to some styles in your theme, or some javascript problems (perhaps a conflict with other code on your page or from another block). Or if you've made modifications to the block's view.php file you might have inadvertantly changed something...
If you don't mind, please post an issue for this on github -- from there it will be easier to discuss back and forth and to see some code. Also if you have this running on a publicly-available site, if you could provide a url I could take a look myself (or if you want to send me that directly you can email me at jordan@concrete5tricks.com).
-Jordan
This is a totally brilliant addon, clean / dry and so very useable. You have made developing with concrete5 so accessable to many people (like me). Thank you!
That aside, I've hit a wall trying to add steps into the form flow. Initially i thought to add a conditional statement in the view_form_fields template or controller that looks for set status flags and outputs more fields as required. I have got a bit stuck/failed so far. Is there an existing solution or could you suggest anything. My php logic is a little clunky at times!
Best regards
Robert
What are you trying to achieve? I can offer some pointers, but depending on how complex your requirements are, it's possible that it would need some more advanced programming to do, in which case you might be better off with one of the advanced form blocks in the marketplace that offers more conditional logic features.
But let me know what it is you want to do and I'll see what I can offer to help.
-Jordan
Basically, i was trying to create a stepped form whilst still utilising the form helper for validation along the way (a server side method rather than with js).
I did try ProForms but the stepped form function is only frontend/js and by the time I'd layed out all my form items, validation and conditional elements across the steps became troublesome from a 'user journey' perspective and form building alike.
So I wondered about conditionally calling different templates or validate functions for each step and sticking them together somehow for processing etc. Or maybe discrete error flags or maybe posting each section to another form (ugly). How the mind wanders.
I'm sure it would be usefull to others too and you are the c5 package God as far as I'm concerned so thought it wouldn't hurt to ask what your take on it might be?
Hmm... that is rather complicated. I appreciate that you're trying to do it without javascript (I am a big believer in making things work without javascript when it's not necessary), but it does often involve a bit more effort.
The main challenge with this is that the block controller makes a big assumption that the form POST contains all of the data needed to save a submission record... but if you split it up into multiple submissions then you can't easily rely on the built-in data models and controller functionality of the addon.
Perhaps a different approach to take would be adding a hidden "step" input to your form fields, then in PHP you check if that "step" value exists in the POST data and if so, output a different "action" in the form tag and different questions on the form fields? So the only form that actually submits to the block's usual "action" is the final step, but all prior steps submit to a new action that you add to the controller, which simply takes the POSTed data and passes it back to the view to be outputted in more hidden fields. In this way, the data from each step is collected and passed along to the next step in hidden form fields. Then the final step takes all of the submitted data (all the hidden fields from prior steps' data plus the normal form fields for the final step form) and does the normal "save to database" stuff that the block controller usually does when handling a submission.
I guess it depends on how complex your form logic is though... at the end of the day this addon was built to make a basic contact form as easy as possible, which means it makes a lot of assumptions about how the form will work. If you need the form to work differently than those assumptions, unfortunately this might not be the right code to use.
Best of luck,
Jordan
Thank you for your suggestions - I'll see where I end up with this.
Robert
Thank you very much in advance
I have not yet seen a version that works with 5.7.
-Jordan
That sounds like some sort of javascript conflict with scripts you are including as part of your form markup. If you can head over to the github page and submit an issue there ( https://github.com/jordanlev/c5_custom_contact_form/issues ), I can try to help you figure it out.
-Jordan
Cheers,
Jake.
Cheers,
Jake.
Commenting has been disabled.