HTML/PHP Feedback form: Email Submit

This forum is for all Flare issues not related to any of the other categories.
Post Reply
arshabhirai
Propeller Head
Posts: 44
Joined: Tue Feb 28, 2017 12:15 pm

HTML/PHP Feedback form: Email Submit

Post by arshabhirai »

Hi all,
I have added a feedback button on the master page; when a user clicks the button, a popup modal opens that has a text area and a button to submit their feedback. The frontend part is done, but I am struggling to make the PHP script work for email submission. I am not sure if this even possible with Flare :(.
Has anyone done this before? I would appreciate any help at this stage.
trent the thief
Propellus Maximus
Posts: 613
Joined: Wed Feb 01, 2006 6:21 am
Location: Off in the dark....

Re: HTML/PHP Feedback form: Email Submit

Post by trent the thief »

You'll probably need to use an iframe and access the PHP on your server from there. Flare doesn't know how to use PHP code.

Take a look at this thread: viewtopic.php?f=9&t=13293&start=0
Trent.

Certifiable.

Image

umm...
I meant MAD Certified.

Official Propeller Beanie Owner :-)

:flare: Are you on Flare's Slack channels? PM me for an invitation! :flare:
RamonS
Senior Propellus Maximus
Posts: 4293
Joined: Thu Feb 02, 2006 9:29 am
Location: The Electric City

Re: HTML/PHP Feedback form: Email Submit

Post by RamonS »

The action of the form submit needs to point to the PHP script on your site. Once the script gets the form content posted the front end is done with its work. Can you share the HTML of the popup?
arshabhirai
Propeller Head
Posts: 44
Joined: Tue Feb 28, 2017 12:15 pm

Re: HTML/PHP Feedback form: Email Submit

Post by arshabhirai »

trent the thief wrote:You'll probably need to use an iframe and access the PHP on your server from there. Flare doesn't know how to use PHP code.

Take a look at this thread: viewtopic.php?f=9&t=13293&start=0
Thanks for your reply. Could you please explain a bit more. I am completely new to PHP.
arshabhirai
Propeller Head
Posts: 44
Joined: Tue Feb 28, 2017 12:15 pm

Re: HTML/PHP Feedback form: Email Submit

Post by arshabhirai »

RamonS wrote:The action of the form submit needs to point to the PHP script on your site. Once the script gets the form content posted the front end is done with its work. Can you share the HTML of the popup?
Hi RamonS,
Thank you for your reply.
Here is my HTML that I have added to the master page:

Code: Select all

<!--Feedback popup modal-->
        <div id="myModal" class="modal">
            <div id="modal-box" class="modal-content">
                <div class="modal-header"><span class="close">×</span>
                    <h2>Have Feedback or a Question For Us?</h2>
                </div>
                <div class="container">
                    <form action="mailer.php" method="post"><textarea type="text" id="subject" name="message" placeholder="Please write your comments about this topic." style="height:200px"></textarea>
                        <input type="submit" value="Send" />
                    </form>
                </div>
            </div>
        </div>
        <!--Animated feedback button -->
        <div id="myBtn">
            <button id="popup" class="feedback-button" onclick="toggle_visibility()">Comments</button>
        </div>
For testing purposes, I placed the PHP script in the MasterPages folder, but it did not work. If I test it with one single page, I think, it will work.

Also, do I need to add the PHP script separately to the server?

Many thanks!
A
trent the thief
Propellus Maximus
Posts: 613
Joined: Wed Feb 01, 2006 6:21 am
Location: Off in the dark....

Re: HTML/PHP Feedback form: Email Submit

Post by trent the thief »

I wasn't sure if you trying to build the form using PHP output to a flare page.Since the form is just html, I think if you add the full URL to the form action it should start working.

<form action="http://mysite.com/path/to/mailer.php"....
Trent.

Certifiable.

Image

umm...
I meant MAD Certified.

Official Propeller Beanie Owner :-)

:flare: Are you on Flare's Slack channels? PM me for an invitation! :flare:
RamonS
Senior Propellus Maximus
Posts: 4293
Joined: Thu Feb 02, 2006 9:29 am
Location: The Electric City

Re: HTML/PHP Feedback form: Email Submit

Post by RamonS »

I'm with trent. If the script on the server doesn't fire it is because the action points to a file local to the current file. That only works if the file is local to all pages. Add the full path and try again. If that still doesn't yield the desired results use the dev tools in the browser and the logs from the web server to find out where your form submit is going.
arshabhirai
Propeller Head
Posts: 44
Joined: Tue Feb 28, 2017 12:15 pm

Re: HTML/PHP Feedback form: Email Submit

Post by arshabhirai »

Thanks, guys. Yes, makes sense to add the full path. I will try that today. Cheers!
arshabhirai
Propeller Head
Posts: 44
Joined: Tue Feb 28, 2017 12:15 pm

Re: HTML/PHP Feedback form: Email Submit

Post by arshabhirai »

I have added the full URL in the action attribute and looks like it will work -- getting there!
When I click the submit button, instead of running the script, the ‘mailer.php’ page opens in the browser, and all the codes are displayed. Two possible reasons: our server does not support PHP (I have already talked with the IT folks and they are checking it for me), or the script is bad.

Here is my html and the script:

HTML:

Code: Select all

<!--Feedback popup modal-->
        <div id="myModal" class="modal">
            <div id="modal-box" class="modal-content">
                <div class="modal-header"><span class="close">×</span>
                    <h2>Have Feedback or a Question For Us?</h2>
                </div>
                <div class="container">
                    <form action="http://xxxxxxxxx/mailer.php" role="form" id="feedback_docs" method="post"><textarea id="subject" name="Message" placeholder="Please write your comments about this topic." style="height:200px"></textarea>
                        <input name="submit" type="submit" value="Send" />
                    </form>
                </div>
            </div>
        </div>
        <!--Animated feedback button on right-->
        <div id="myBtn">
            <button id="popup" class="feedback-button" onclick="toggle_visibility()">Comments</button>
        </div>
PHP:

Code: Select all

<?php
//Message Vars
$name = $message '';

//Check For Submit
if(isset($_POST["submit"])){
// Checking For Blank Message
if($_POST["Message"]==""){
echo "Please write your message.";
}else{
$message = $_POST['Message'];
// Message lines should not exceed 600 characters (PHP rule), so wrap it
$message = wordwrap($message, 600);
// Send Mail By PHP Mail Function
mail("xxxxxx@xyz.com", "Feedback from customer documentation site", $message);
echo "Your message has been sent successfuly ! Thank you for your feedback";
}
}
?>
I will test some more scripts tomorrow.
arshabhirai
Propeller Head
Posts: 44
Joined: Tue Feb 28, 2017 12:15 pm

Re: HTML/PHP Feedback form: Email Submit

Post by arshabhirai »

It finally worked and here is the script I used:

Code: Select all

<?php
 $comments = $_POST['comments'];
 $to = 'example@example.com';
 $subject = 'Feedback received from customer documentation website';
 $url = "http://".$_SERVER['HTTP_REFERER'];
 $from = 'feedback@example.com'; 
 $headers[] = 'From: $from';
 $headers[] = 'MIME-Version: 1.0';
 $headers[] = 'Content-type: text/html; charset=iso-8859-1';
  
 $body = "\r\r Message: \r\r $comments";

//I am not too happy with the post submission  "thank you" message as it opens in a new page. I have to figure out how to stay on the same page after message submission.

if ($_POST['submit']) {
    if (mail ($to, $subject, $url. $body, implode("\r\n",$headers))) { 
        echo '<p>Your message has been sent! Back to <a href="index.htm">Customer Documentation</a>.</p>';
    } else { 
        echo '<p>Something went wrong, go back and try again!</p>'; 
    }
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>
Some things to note:
You will need PHP installed in your web server, and you may also need to configure PHP installation for sending mail ( if you're not using your local SMTP server). You will find many instructions online to do so.

If you look at my script, I have added

Code: Select all

$from
in the header, as the mail was being sent as <apache@servername.domain.com, which was getting flagged as spam. I had to ask the IT folks to whitelist that particular email, as well as added the

Code: Select all

$from
header.

And, I also added the $url variable, which sends the URL of the current page along with the message. It took me a while to figure this out.

I have tested these in the sandbox and everything is working properly. I still have to update the text and make some frontend changes, but the PHP mail configuration looks good.
TopNavNewbie
Jr. Propeller Head
Posts: 5
Joined: Tue Mar 14, 2017 8:40 am

Re: HTML/PHP Feedback form: Email Submit

Post by TopNavNewbie »

Hi arshabhirai,

I've never used PHP before but am really interested in adding the feedback form to my Flare project.

Sorry for the basic questions, but did you create the PHP code file in Notepad and then save it in the Scripts folder of your Flare project? If yes, where do you insert the PHP script in your master page? Was it in the header or closer to your HTML?

Also, in the PHP code you used, what are the variables that I would need to update with my own details? I presume the $to = 'example@example.com'; part but any others too?

Any help you could please give me would be most appreciated :)
RamonS
Senior Propellus Maximus
Posts: 4293
Joined: Thu Feb 02, 2006 9:29 am
Location: The Electric City

Re: HTML/PHP Feedback form: Email Submit

Post by RamonS »

TopNavNewbie wrote:Sorry for the basic questions, but did you create the PHP code file in Notepad and then save it in the Scripts folder of your Flare project? If yes, where do you insert the PHP script in your master page? Was it in the header or closer to your HTML?
Also, in the PHP code you used, what are the variables that I would need to update with my own details? I presume the $to = 'example@example.com'; part but any others too?
I think I can answer some questions
- yes, you create the PHP file in a text editor. Notepad will work if you do not have anything better. At least get Notepad++. If you want to dive in head first and do more with PHP get a real IDE, such as NuSphere's PHPEd (can get a bit pricey, but worth the expense). Unfortunately, the only decent somewhat free PHP IDE from Waterproof is no longer available. You could also use Eclipse if your are really interested in a lot of pain and frustration.
- PHP script is included in the body of a page, not the header. Typically, you paste that bit of script right into the page or write some PHP code to load the script from an external file to be executed right then and there.
- the only variable that needs changing is the email address. The rest for email server connections is configured in the PHP ini file.

You may want to browse the absolutely excellent PHP documentation at http://php.net/manual/en/. W3Schools also has some decent basic guides on how to get started with PHP, see https://www.w3schools.com/php/default.asp.

You will definitely need a web server with PHP enabled. Doing this for Apache is easy and well documented. IIS can also have PHP, but as anything with IIS it takes a team of IT experts to get it working...or maybe I'm just too dumb, your choice. There are instructions for IIS as well.

When the web server comes across the php tags in an html file to be served up, the server executes the script and returns the resulting html to the client.
arshabhirai
Propeller Head
Posts: 44
Joined: Tue Feb 28, 2017 12:15 pm

Re: HTML/PHP Feedback form: Email Submit

Post by arshabhirai »

TopNavNewbie wrote:Hi arshabhirai,

I've never used PHP before but am really interested in adding the feedback form to my Flare project.

Sorry for the basic questions, but did you create the PHP code file in Notepad and then save it in the Scripts folder of your Flare project? If yes, where do you insert the PHP script in your master page? Was it in the header or closer to your HTML?

Also, in the PHP code you used, what are the variables that I would need to update with my own details? I presume the $to = 'example@example.com'; part but any others too?

Any help you could please give me would be most appreciated :)
Sorry for this super tardy response. There were several workarounds that I had to implement.

1. I created a separate php file and placed it in the contents folder.
2. Yes, the PHP script is linked on the MasterPage page and I have created an iframe to display the confirmation message or a validation error message. Example:

Code: Select all

<form action="https://documentation.com/form.php" role="form" name="feedbackForm" id="feedbackForm" onsubmit="return validateForm()" method="post" target="submit.frame">Form details</form><iframe href="https://documentation.com/" id="submit.frame" name="submit.frame" onLoad="injectJS()"></iframe>
2. I also created a JS file for validation on-submit. I wanted a simple feedback form with text input box and a submit button. If you intend to add other input fields, you will need some form of validation for those fields as well.
3. You need to add some script to make sure the form reloads on click to clear up the previous inputs and confirmation/error message, see onLoad="injectJS() above.
4. Lastly, you will need to block all spam messages. I have used the honeypot trick and Google's invisible reCaptcha.
arshabhirai
Propeller Head
Posts: 44
Joined: Tue Feb 28, 2017 12:15 pm

Re: HTML/PHP Feedback form: Email Submit

Post by arshabhirai »

Here is what I've got at the moment:
Feedback-Example.png
I have added a button on the master page. When users click the button, it triggers a script to open the feedback form.
You do not have the required permissions to view the files attached to this post.
Post Reply