Score:0

How to display a content-management-system-agnostic contact form I have developed, just without iframe?

sg flag

I have developed a simple, content-management-system-agnostic[1] PHP-HTML-JavaScript-CSS contact form which I normally embed by iframe but I no longer want to use iframe due to the form appearing partially in mobile display with scrolling needed to view all of it.

I can use this CSS as a partial solution:

@media screen and (max-width:733px) {
    #prcf_iframe {
        height:547px;
    }
}

This is neither a "pixel perfect" solution nor anything near pixel perfect because in some mobile displays the form either still has some scrolling area or, in other mobile displays, suddenly has some extra "dead height area".


How could I show this CMS-agnostic form in Drupal without using iframe?
1. Due to the form being CMS-agnostic by design, it should also not be part of a Drupal module.

Jaypan avatar
de flag
Is the form HTML only? Where happens upon submission - is data submitted? Pulled from a remote API? Sent to a remote API?
sg flag
@Jaypan the form is PHP files containing HTML, as well as a JS file and CSS file/s. The data is submitted to my Gmail account so I don't fear of SQL injection.
Jaypan avatar
de flag
You can try pasting it all into the body of a node, as-is. Make sure the node body allows full text.
sg flag
@Jaypan the form source code is somewhat modular and is comprised of various files and directories. I can make one big cluster but I prefer not to because it makes it hard for me to maintain the code ("a typo in line 500"). Perhaps you meant to compile everything to HTML before but sadly I don't know such a compiler that will make one giant HTML out of all.
Jaypan avatar
de flag
Well, either that, or do it the proper Drupal way. But you don't want to do it the proper Drupal way, so your options are limited. I guess the other option is to drop the file in your filesystem and link to it - Drupal will not be instantiated in the case that an actual file exists. You won't get anything Drupal at all though, including the theme or anything.
sg flag
@Jaypan I am open to do it in the Drupal way as well (contact or webform) but if I can use that particular CMS-agnostic form is best, at least in some circumstances. I didn't quite understood `drop the file in your filesystem and link to it` if you mean to make it a standalone file without the theme aesthetics than no, I agree I shouldn't do that.
Jaypan avatar
de flag
Drupal ways would be to create a module and use the Form API to build your form, alter a webform, or alter a contact form. You would then attach your CSS/JS to the form whichever method you choose.
Jaypan avatar
de flag
And yes, you understood me correctly about dropping the file into your file system.
apaderno avatar
us flag
Showing a CMS-agnostic form in Drupal is a bad idea. If the purpose is entering data an external API would use, a Drupal form with a submission handler that sends the data to the external API site is the way to go, when you have already a Drupal site. Clearly, it depends from which type of integration with Drupal is required. I take the integration with Drupal is needed, or you won't show an external page in Drupal.
Score:1
cn flag

A "CMS-agnostic form that is not part of a Drupal module" could also be considered a "third-party PHP script", which is a security risk.

Now, you wrote this code yourself, so you can vouch for it. But, you are basically asking, "how can I inject a PHP script into Drupal?", which is something that Drupal doesn't want you to do as it can circumvent Drupal's various security features.

This means that the answer to your question is "It's hard and there will be compromises."

Here are three approaches you can take.

Approach: Host the script on the same server, but separate it from Drupal

One approach is to host the script in its own directory on your server, and then exclude that directory from Drupal. This exclusion can be done at the server level so Drupal never sees the script and the script doesn't see Drupal.

In this case, the script will not be part of the Drupal site, so you won't have the theme.

The server configuration depends on your server; you can Google it.

Approach: Embed it in an iframe

You said you didn't like scrolling in your iframes, but there are many JS libraries to work around this, such as iframe-resizer. This is a Stack Overflow question though.

Approach: Use Webform

Re-write your form to use the Webform module. Yeah, it won't be CMS-agnostic anymore. But Webform is one of the premier Drupal contrib modules and can do basically anything-- many organizations choose Drupal because of this module. So it can obviously handle a contact form of any complexity, and it will give you full integration with Drupal.

Score:0
id flag

Use the PHP module, at your own risk.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.