custom form in an html block

Permalink
I am trying to build a custom form by using the HTML block. I don't really want a user to be able to edit or modify the content of the form. It will be a unique use form.

On submit the form will fill in the fields of pre-designed PDF form and send the pdf form by email to a predetermined address. I have designed and tested this to work on a non C5 site and it works. However when I copy and paste it into the HTML block it doesn't work. All paths seem to be set accurately and no mail is being generated according to the logs.

I feel like their is an error in the way that C5 sends mail but no errors have been reported in a php info page or C5 logs and it is not being received to the email address.

Is there some trick in how to add custom external calls to php files in the action submit of forms related to C5? Anyone have related experience or tips?

AnotherAndrew
 
jordanlev replied on at Permalink Reply
jordanlev
An HTML block won't run php code.
I have a sample contact form block that sends an email when filled out -- shouldn't be too hard to see how to modify it to suit your needs:
https://github.com/jordanlev/c5_custom_contact_form...
AnotherAndrew replied on at Permalink Reply
AnotherAndrew
> An HTML block won't run php code.

O, yes, duh. Is there a php block? Won't that work?
AnotherAndrew replied on at Permalink Reply
AnotherAndrew
Actually, I am only including javascript and html in the html block. However, the submit goes to a php file. So I should be fine, right?
beebs93 replied on at Permalink Reply
beebs93
The potential problem is that the HTML block will display any JS while in edit mode and if you're not careful (or you just copy and paste a form from an outside source without running though it yourself) then it may interfere with concrete.

I'd take a look at jordan's block first since it's been tested in the c5 environment and won't cause any conflicts.
AnotherAndrew replied on at Permalink Reply
AnotherAndrew
Thanks. I looked at his code and there are some areas that I need that I don't think his example can provide. So I guess I am stuck writing it myself.

However, it still seems irrelevant. I should be able to put any html, js, css in a html block and it would work. Like I mentioned, I have tested this form outside of c5 and it works.
beebs93 replied on at Permalink Reply
beebs93
Yes, you can put any HTML, JS and/or CSS into an HTML block, but remember that when you go into edit mode that everything (including the JS you enter) will still be there.

My point is that regardless if it works *outside* of concrete5 doesn't automatically mean it will *inside* when you view the page in edit mode.

If it's written properly then it shouldn't be a problem; it's just something to be aware of.
jordanlev replied on at Permalink Reply
jordanlev
I think you might be misunderstanding how forms work. Yes you should be able to put any html and css into an HTML block and have it work (assuming it's just a portion of HTML, not an entire page, and assuming it's correct and valid html). But if that html/css includes image paths, you're going to need to put in a full absolute URL to wherever those images live -- you can't just do <img src="images/mypicture.jpg" /> because the html is going to run from the page that the user is visiting, and your "images" directory (or wherever it is you're storing images) is not going to be in the same relative location. Instead you need to figure out where it is your images are and do something like this: <img src="http://mydomain.com/themes/mytheme/images/mypicture.jpg" />.

As for javascript, you should *probably* be able to put anything in there, but there is much more possibility for conflicts with other javascript that the page is loading (which you wouldn't have to deal with when making your own isolated page outside of C5). Also, a common cause of problems is people including the jQuery library in their own javascript -- don't do this because C5 always includes that automatically on every page and if you include it too they will conflict with each other.

Learn how to use Firebug (for Firefox) or Web Inspector (for Chrome or Safari) to diagnose Javascript issues -- this will help immensely.

Finally, and this is the big one... while you should be able to make html/css/js work in the page, when the form is submitted it needs to GO somewhere -- you say you have a php file that handles that, but where is that php file? This is what is going to cause the most problems if you want that integrated into C5 somehow. On the other hand, if that php file is self-contained and does its own thing just fine, you could put it on a server somewhere and post directly to it (but note that any errors or messages it outputs will be outside of C5 and hence not in your site's theme).

Hope this sheds a little light on the complications involved. Best of luck.
AnotherAndrew replied on at Permalink Reply
AnotherAndrew
Thanks Jordan.

> On the other hand, if that php file is self-contained and does its own thing just fine, you could put it on a server somewhere and post directly to it (but note that any errors or messages it outputs will be outside of C5 and hence not in your site's theme).

All of my code is valid, and my js does not conflict. I have tried placing the form's php script both on another host, and on the host of the site, in the root directory and in the theme directory. Every path is absolutely referenced. Still no success.

This is why I am now wondering if it could be a problem with my host. However, I do not know what it might be. As I said earlier my phpinfo page gave no indication of mail errors. This is why I am stumped!
Highlight replied on at Permalink Reply
Is it possible to make this form redirect to a popup window saying.
Thank for the message ?
jordanlev replied on at Permalink Reply
jordanlev
That would require some custom coding. If you're not a programmer then I don't think it's going to be possible. If you are a programmer, the general idea is that you'd need to submit the form via Ajax (I'd use the jquery.form library, since it's already part of C5), have a "tools" file that responds to the ajax request, then have some front-end code that displays the popup window. (You'll need to include the popup window library as well, for example "fancybox" or "colorbox").