Author Topic: Possible to implement formmail or a contact form?  (Read 3854 times)

Attention

  • Newbie
  • *
  • Posts: 23
Possible to implement formmail or a contact form?
« on: June 22, 2009, 01:49:42 pm »
Hello

Im trying to implement a simple contact flash php script, it hasnt worked so far, i get it to load but it doesnt send. The form works on it's own when not implemented in megazine.

Anyone have luck with this?`

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Possible to implement formmail or a contact form?
« Reply #1 on: June 23, 2009, 10:10:42 pm »
Hi,

technically it should be possible. I'm almost sure I already had someone trying this and finally succeeding, too.
Do you test this locally? If so, try moving it to a server (or install wamp and test it on that local server), might be because of the security sandbox...

Regards,
Florian
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

maxie

  • Jr. Member
  • **
  • Posts: 43
Re: Possible to implement formmail or a contact form?
« Reply #2 on: June 28, 2009, 12:15:09 am »
I cannot get them working here, either. It is a pity. A form for the book would be a nice add-on. I have tried several forms/scripts:

- Mailform versions using SWF, XML and PHP would usually say that they cannot find the XML file, although it is in the same directory. (Is there a conflict between the megazine.xml and the xml file for the form?)
- Another mailform without an additional XML, i.e. using "only" the SWF and PHP (this one: http://maxie-online.de/#/32) "pretends" to be sending, but actually it does not send at all.

All the forms I tried work fine when the SWF is embedded in a  HTML page. But as soon as I take the SWF and put it on a book page, the form would not work any more.

It would be nice to hear from those who got their  form working to share with us how they did it.

Kind regards,
Maxie

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Possible to implement formmail or a contact form?
« Reply #3 on: July 06, 2009, 05:33:56 pm »
Hmm... most likely some sandboxing problem. I'll have a look into this myself when I find the time.
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

Attention

  • Newbie
  • *
  • Posts: 23
Re: Possible to implement formmail or a contact form?
« Reply #4 on: September 25, 2009, 07:21:21 pm »
any recent resolution on this? would love to hear

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Possible to implement formmail or a contact form?
« Reply #5 on: September 25, 2009, 08:06:25 pm »
Haven't tried this with the 1.38 version, but in the 2.x version the following works just fine:

ActionScript 3.0 part (the swf with the form loaded into the book):
Code: (actionscript3)
  1. stop();
  2.  
  3. // request related vars and setup
  4.  
  5. var variables:URLVariables = new URLVariables();
  6. var variableLoader:URLLoader = new URLLoader();
  7. var variableSend:URLRequest;
  8.  
  9. import de.mightypirates.megazine.interfaces.IMegaZine;
  10.  
  11. // initialize request var with path relative to megazine.swf
  12. function megazineSetup(megazine:IMegaZine):void {
  13. variableSend = new URLRequest(megazine.getAbsPath("form_eval.php"));
  14. variableSend.method = URLRequestMethod.POST;
  15. variableSend.data = variables;
  16. }
  17.  
  18. // perform the request
  19. function sendFormData():void {
  20. variables.username = txtName.text;
  21. variables.email = txtMail.text;
  22. variableLoader.load(variableSend);
  23. }
  24.  
  25. // build form
  26.  
  27. graphics.beginFill(0, 0.5);
  28. graphics.drawRect(0, 0, 100, 75);
  29. graphics.endFill();
  30. var txtName:TextField = new TextField();
  31. txtName.width = 100;
  32. txtName.height = 25;
  33. txtName.type = TextFieldType.INPUT;
  34. txtName.background = true;
  35. txtName.border = true;
  36. addChild(txtName);
  37. var txtMail:TextField = new TextField();
  38. txtMail.width = 100;
  39. txtMail.height = 25;
  40. txtMail.type = TextFieldType.INPUT;
  41. txtMail.background = true;
  42. txtMail.border = true;
  43. txtMail.y = 25;
  44. addChild(txtMail);
  45. var btnSend:SimpleButton = new SimpleButton(buildState(0), buildState(1), buildState(2), buildState(0));
  46. btnSend.y = 50;
  47. addChild(btnSend);
  48.  
  49. // build button states...
  50. function buildState(type:int):DisplayObject {
  51. var s:Sprite = new Sprite();
  52. switch (type) {
  53. case 0:
  54. s.graphics.beginFill(0xFF0000);
  55. break;
  56. case 1:
  57. s.graphics.beginFill(0x00FF00);
  58. break;
  59. case 2:
  60. s.graphics.beginFill(0x0000FF);
  61. break;
  62. }
  63. s.graphics.drawRect(0, 0, 50, 25);
  64. s.graphics.endFill();
  65. return s;
  66. }
  67.  
  68. // gui event stuff
  69. btnSend.addEventListener(MouseEvent.CLICK, handleButtonClick);
  70.  
  71. function handleButtonClick(e:MouseEvent):void {
  72. sendFormData();
  73. }

PHP part for testing if the data arrives:
Code: (php)
  1. <?php
  2. $fileh = fopen("formdata.txt", 'a');
  3. fwrite($fileh, $_REQUEST['username'] . ": " . $_REQUEST['email'] . "\n");
  4. fclose($fileh);
  5. ?>


Just be sure to test this on a server and not locally (in the sense of, test it through a server, even if it's running on your machine, e.g. wamp - meaning the url must start with http:// not with file:///).
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

Attention

  • Newbie
  • *
  • Posts: 23
Re: Possible to implement formmail or a contact form?
« Reply #6 on: September 29, 2009, 11:12:24 am »
Hm could you be so kind to post the .flv file?

i tried pasting this code in flash root, but im guessing i would have to make the graphics - input boxes etc?

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Possible to implement formmail or a contact form?
« Reply #7 on: September 29, 2009, 12:53:58 pm »
The second half of the code does the form building (after // build form)... I mean, I can post the fla, but it's just an new document with the code pasted in :P

You're probably missing the interface (IMegaZine)... either get it and put it to the proper location, oder replace all occurences with '*' and remove the import.

(i.e.
Code: (actionscript3)
  1. import de.mightypirates.megazine.interfaces.IMegaZine;
  2.  
  3. // initialize request var with path relative to megazine.swf
  4. function megazineSetup(megazine:IMegaZine):void {
  5.    variableSend = new URLRequest(megazine.getAbsPath("form_eval.php"));
  6.    variableSend.method = URLRequestMethod.POST;
  7.    variableSend.data = variables;
  8. }

becomes

Code: (actionscript3)
  1. // initialize request var with path relative to megazine.swf
  2. function megazineSetup(megazine:*):void {
  3.    variableSend = new URLRequest(megazine.getAbsPath("form_eval.php"));
  4.    variableSend.method = URLRequestMethod.POST;
  5.    variableSend.data = variables;
  6. }
)
« Last Edit: September 29, 2009, 12:56:16 pm by Florian Nücke »
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

Afroshok

  • Newbie
  • *
  • Posts: 10
Re: Possible to implement formmail or a contact form in 2.0RC
« Reply #8 on: October 15, 2009, 05:10:39 pm »
Hi Florian,

What is the method for this now with the 2.0 RC. the above solution was perhaps for 1.38?

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Possible to implement formmail or a contact form?
« Reply #9 on: October 15, 2009, 10:57:15 pm »
Haven't tried this with the 1.38 version, but in the 2.x version the following works just fine:
[snip]

So no, the above was not explicitly for 1.38 (although it should work with that, too). In 2.x it definitely works.
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

Attention

  • Newbie
  • *
  • Posts: 23
Re: Possible to implement formmail or a contact form?
« Reply #10 on: March 10, 2010, 11:55:25 am »
alright still no luck - is there any easy way just to adapt an exisiting contact as3 form now with the new megazine?

or has anyone got florians to work and is willing to post an example?

Attention

  • Newbie
  • *
  • Posts: 23
Re: Possible to implement formmail or a contact form?
« Reply #11 on: March 10, 2010, 12:58:13 pm »
Alright got it working! sortof!

im not very sharp when it comes to php and as3 but i have a basic knowledge sort of :)

what should be in formdata.txt? and how should i format it ?

where is send to in this php?

      <?php

      $fileh = fopen("formdata.txt", 'a');

      fwrite($fileh, $_REQUEST['username'] . ": " . $_REQUEST['email'] . "\n");

      fclose($fileh);

      ?>
« Last Edit: March 10, 2010, 02:22:19 pm by Attention »

Attention

  • Newbie
  • *
  • Posts: 23
Re: Possible to implement formmail or a contact form?
« Reply #12 on: March 11, 2010, 03:32:56 pm »
Please help :)

getting desperate!

Im willing to exchange some design skills in order to get some help on this contact form / if anyones interested!

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Possible to implement formmail or a contact form?
« Reply #13 on: March 19, 2010, 03:44:06 pm »
The PHP code is just an example. It just opens a text file (named formdata.txt) and writes the received data (from the $_REQUEST variable) into it.

If you don't know how to process the form data on the serverside (i.e. in the PHP / ASP / JSP / Python / Perl / whatever you use) try your favorite
search machine, and it'll gladly help you, I'm sure ;) [because if you're at that point the data get's sent, so it's no longer a Flash / MegaZine3 related
issue; you might as well try a general Flash forum for that, then]
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

Attention

  • Newbie
  • *
  • Posts: 23
Re: Possible to implement formmail or a contact form?
« Reply #14 on: April 06, 2010, 05:00:41 pm »
Ok florian still struggling with this tried adopting a simple as3 / php form with validation - The mail goes through sort of But i only get one line in the mail which is "Fra:" and thats it
this is my as3 code

Code: (actionscript)
  1. stop();
  2.  
  3.  
  4. var emailData:URLVariables = new URLVariables();
  5. var request:URLRequest;
  6. var loader:URLLoader = new URLLoader();
  7. import de.mightypirates.megazine.interfaces.IMegaZine;
  8.  
  9. // initialize request var with path relative to megazine.swf
  10.  
  11. function megazineSetup(megazine:IMegaZine):void {
  12.    request  = new URLRequest(megazine.getAbsPath("email.php"));
  13.    request.method = URLRequestMethod.POST;
  14.    request.data = emailData;
  15.    loader.load(request);
  16. }
  17.  
  18. sendKnap.addEventListener(MouseEvent.CLICK, sendMail);
  19. loader.addEventListener(Event.COMPLETE, mailSendt);
  20.  
  21. function sendMail(e:MouseEvent){
  22.    if(validere()){
  23.        statusField.text = "Sender mail, vent venligst...";
  24.  
  25.        emailData.navn = navnInput.text;
  26.        emailData.email = emailInput.text;
  27.        emailData.besked = beskedInput.text;
  28.  
  29.    }else{
  30.        statusField.text = "Udfyld venligst alle felter."
  31.    }
  32. }
  33.  
  34. function validere():Boolean
  35. {
  36.    if(navnInput.text != "" && emailInput.text != "" && beskedInput.text != "")
  37.    {
  38.        return true;
  39.    }else{
  40.        return false;
  41.    }
  42. }
  43.  
  44. function mailSendt(e:Event){
  45.    trace("mail sendt")
  46.    statusField.text = "Din besked er nu sendt!"
  47.    navnInput.text = "";
  48.    emailInput.text = "";
  49.    beskedInput.text = "";
  50. }

my php

Code: (php)
  1. <?php
  2. $sendTo = "name@mail.com";
  3. $subject = "Besked fra min mail form. ";
  4. $headers = "From: " . "Min mail form " . "<" . $_POST["email"] .">";
  5. $message = "Fra: ". $_POST["navn"] . "\n\n" . $_POST["besked"];
  6.  
  7. mail($sendTo, $subject, $message, $headers);
  8.  
  9. ?>


// fnuecke: made those code tags more readable
« Last Edit: April 07, 2010, 07:55:13 pm by Florian Nücke »