Search Unity

A bit of help with an in app PHP contact form. Is this the right place?

Discussion in 'Scripting' started by marcipw, Sep 19, 2014.

  1. marcipw

    marcipw

    Joined:
    Apr 18, 2013
    Posts:
    239
    Hello,

    I am sure this is a very simple thing for most of you here. There is something I am not getting and I was hoping for a friendly pointer.

    I have a php form which works well with my MMF Fusion created application (which is all visual scripting) and I want to use the same form (the server side php file) in Unity in the same way.

    Code (CSharp):
    1. <?php
    2. $eaddress = $_REQUEST['eaddress'];
    3. $recipient = "dude@confidentialxwebsite.com";
    4. $companyname = $_REQUEST['companyname'];
    5. $siteaddress = $_REQUEST['siteaddress'];
    6. $siteaddress2 = $_REQUEST['siteaddress2'];
    7. $siteaddress3 = $_REQUEST['siteaddress3'];
    8. $siteaddress4 = $_REQUEST['siteaddress4'];
    9. $siteaddress5 = $_REQUEST['siteaddress5'];
    10. $contactnumber = $_REQUEST['contactnumber'];
    11. $sigauth = $_REQUEST['sigauth'];
    12. $widget1 = $_REQUEST['widget1'];
    13. $w1quantity = $_REQUEST['w1quantity'];
    14.  
    15.  
    16. $subject = "You have a Collection Request From $companyname on ".date("d-m-Y");
    17. $mailtext = "<html><head><title>A collection Request</title></head><body><p>COLLECTION DETAILS</p><p><b>Company Name:</b><br />$companyname</p><p><b>Site Address:</b><br />$siteaddress<br />$siteaddress2<br />$siteaddress3<br />$siteaddress4<br />$siteaddress5</p><p><b>Contact Number:</b><br />$contactnumber</p><p><b>Name of Person Authorising Signature:</b><br />$sigauth</p><p><b>Email Address:</b><br />$eaddress</p><br/><p>WIDGETS</p><p>widget1: $widget1<br/>Quantity: $w1quantity</p></body></html>";
    18.  
    19. // To send HTML mail, the Content-type header must be set
    20. $headers  = 'MIME-Version: 1.0' . "\r\n";
    21. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    22. $headers .= 'From: Confidential X Collection App <collectionapp@confidentialxcompany.com>' . "\r\n";
    23.  
    24. mail($recipient, $subject, $mailtext, $headers);
    25. ?>
    I had a look at the wwwform examples but can not figure out how to get unity to speak to this file which is stored on a server.

    I am a complete programming noob when it comes to Unity! I am more of an art guy with a few html, css skills. I can figure most things out via determination and learning by doing but I mainly rely on visual programming assets like Playmaker for Unity stuff. I do find html quicker, easier and more efficient coded by hand in notepad than using a WYSIWYG editor though.

    Running through examples from the beginner tutorial sections on the unity site (spinning cubes, coloring cubes - getting Michael Jacksons face to appear on a plane by downloading the texture using the example here: http://docs.unity3d.com/ScriptReference/WWW.html ) it looks like you can do a massive amount in Unity with a small amount of code and it seems quite simple to get Unity to communicate with the web.

    I thought I was headed in the right direction with this example I found elsewhere on the forums but it is just not happening. Is this even slightly right?

    Code (CSharp):
    1. function OnMouseDown () {
    2.  
    3. var url:String = "http://www.confidentialxcompany.com/appemail/appemail.php";
    4. var form:WWWForm = new WWWForm();
    5. form.AddField("companyname","companyname");
    6. form.AddField("siteaddress","siteaddress");
    7. form.AddField("email","email");
    8. var www:WWW = new WWW(url,form);
    9. yield www;}
    ---
    I am not looking for the full solution by the way just a nudge in the right direction.
    In Fusion I do this to send the data from my editable text boxes:

    Add POST data "companyname" = Edittext$( "companyname" )

    "http://www.confidentialxcompany.com/appemail/appemail.php" + "?subject=" + Edittext$( "companyname" ) + Edittext$( "eaddress" ) + Edittext$( "contactnumber" ) + Edittext$( "sigauth" ) + Edittext$( "siteaddress" ) + Edittext$( "siteaddress2" ) + Edittext$( "siteaddress3" ) + Edittext$( "siteaddress4" ) + Edittext$( "siteaddress5" ) + Edittext$( "widget1" ) + Edittext$( "w1quantity" )

    If I could just find out how to send one bit of data from one input box from Unity I will be a happy man.
    Thanks for looking. I also posted this question in the Unity support forum but have not had any response so thought I might possibly be in the wrong section.

    Any help will be greatly appreciated. P.S. Please don't hate me for being stupid :)
     
  2. marcipw

    marcipw

    Joined:
    Apr 18, 2013
    Posts:
    239
    Yes!
    The code in an old topic has just helped me communicate with the php file via unity!

    Code (CSharp):
    1. function Update()
    2. {
    3.  
    4.    if(Input.GetMouseButtonDown(0))
    5.     var url:String = "www.confidentialxcompany.com/appemail/appemail.php";
    6.     var form:WWWForm = new WWWForm();
    7.    
    8.     form.AddField("companyname","companyname");
    9.     form.AddField("siteaddress","siteaddress");
    10.    
    11.     var www:WWW = new WWW(url,form);
    12.  
    13.  
    14.     Debug.Log("Sending mail");
    15. }