I need to write a code which can do following using actionscript:
1. Send the variables to a php
2. php should open a [re designed word document.
3. Specific word document entries should be replaced with the variables sent from actioncript retaining the formatting of the template.
4. Save the document and provide a link for its download OR just mail it to an address.
I have asked few questions before which very pretty simple compared to this and i did not get any answer for it.. I dont know if this will either. If possible please help me.
To send the variables from ActionScript you would need to do something like the following:
var http:HTTPService = new HTTPService();
http.url = "http://www.yourWebsite.com/yourPhpFile.php";
http.method = "POST";
var variablesToSend:Object = new Object();
for (var varName:String in yourVariables){
variablesToSend[varName] = yourVariables[varName];
}
http.send(variablesToSend);
From "yourPhpFile.php" I would suggest adding some special keywords to search for in the template and do a str_replace() with the variables received through the $_POST object. I'm no php expert but something like:
$yourFilePath = "C:\your\file\path\here.txt";
$yourFileAsString = file_get_contents($yourFilePath);
foreach($_POST as $key=>$value){
$yourFileAsString = str_replace($key,$value,$yourFileAsString);
}
file_put_contents(genNewFileName(),$yourFileAsString);
Related
Wizzards :)
I really want to use Quill richtext editor but I have no real knowledge of JSON or how is parses the so called "Deltas".
Basically, I need to collect the page from the editor and process it with php before storing it in the mysql database, and, from the database back to the editor if user wishes to update an existing post. It needs to be able to parse text and multiple images...
I don't have 3 months a piece to learn js/json, can anyone help me out with this one? Thank youuu!
So acording to the Quill documentation (https://quilljs.com/docs/api/) you can use var delta = quill.getContents(); to collect the data. Would it be something like this with an onclick() function? I dont even know with js if it has to be within a form? remember I don't know js :)
<script>
onclick(does this); // or can it be updated as the user creates the document?
var delta = quill.getContents();
// what then?
</script>";
The php would require a different variable if each image to be processed, perhaps in an array?
<?php
$images = array();
$images[0] = 'json/delta/quill image?';
$images[1] = 'etc...';
$images[2] = 'etc...';
$images[2] = 'wtf...';
?>
Why on earth they don't have a simple example of how to do this I don't know, its an all too common problem with these things.
I've got a problem that's either insanely simple or complex, it's up to you to find out. I've been working on trying to incorporate the URL Loader class into the beginners graphics program - Stencyl. I am fluent in HTML, CSS and PHP but actionscript is completely new to me so I really could use with a hand. Here's what I've got:
There are 4 files hosted on my domain:
Webpage.html
Stylesheet.css
RequestData.php
FlashDoc.swf
The html and css code is simple, no problems there and the swf file embed in the html document. The flash file is a simple form with a text field, submit button and two dynamic text fields. The code goes as follows:
// Btn listener
submit_btn.addEventListener(MouseEvent.CLICK, btnDown);
// Btn Down function
function btnDown(event:MouseEvent):void {
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
// Be sure you place the proper location reference to your PHP config file here
var varSend:URLRequest = new URLRequest("http://www.mywebsite.com/config_flash.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.uname = uname_txt.text;
variables.sendRequest = "parse";
// Send the data to the php file
varLoader.load(varSend);
// When the data comes back from PHP we display it here
function completeHandler(event:Event):void{
var phpVar1 = event.target.data.var1;
var phpVar2 = event.target.data.var2;
result1_txt.text = phpVar1;
result2_txt.text = phpVar2;
}
}
I then have a small PHP file with this code:
<?php
// Only run this script if the sendRequest is from our flash application
if ($_POST['sendRequest'] == "parse") {
// Access the value of the dynamic text field variable sent from flash
$uname = $_POST['uname'];
// Print two vars back to flash, you can also use "echo" in place of print
print "var1=My name is $uname...";
print "&var2=...$uname is my name.";
}
?>
This is, for some reason, not working. The result is just two blank text fields and being an actionscript noob, I have no idea what is up. Any help would be greatly appreciated. Thank you for your time.
The answer to your issue is both simple and surprising, if you're not used to AS3.
In AS3, the flash.* classes tend to, when a setter is used, make and store a copy of the passed object.
Since they store a copy, any modification on the original instance after the setter isn't applied on the copy, and thus is ignored.
It is the case of, for example, DisplayObject.filters, ContextMenu.customItems or URLRequest.data.
In your code, you are setting varSend.data = variables before filling variables. You should do the reverse :
variables.uname = uname_txt.text;
variables.sendRequest = "parse";
varSend.data = variables;
// Send the data to the php file
varLoader.load(varSend);
Only some classes do that, and even then, they usually don't do it with all of their setters.
I am mediocre with php and ignorant with XML...if you can be detailed it will help me learn.
I am attempting to use PHP programming to execute a scripts to this link... http://ws.geonames.org/postalCodeSearch?postalcode=VARIABLE_ZIP&country=US. The VARIABLE_ZIP is the actual zip code entered into the form that will submit the information in the link above. The output of that link creates an XML page that i do not want displayed anywhere on my website.
What I want to do is capture the XML data Latitude and Longitude values as variables within php and store them into a database.
1) I have a form
2) The user inputs their zip code into the form
3) upon submitting the form: I want code to capture the XML data generated by the link with the zip code variable added: http://ws.geonames.org/postalCodeSearch?postalcode=90210&country=US (I don't want this page to display anywhere, I just want to capture the data)
4) I want to take those variables back to PHP so I can store them in my database
*Step 3 is an unknown process for me.
This is what the XML code generates on a separate page...(i don't want a page to display):
= = = = =
<geonames>
<totalResultsCount>1</totalResultsCount>
<code><postalcode>90210</postalcode>
<name>Beverly Hills</name>
<countryCode>US</countryCode>
<lat>34.09011</lat>
<lng>-118.40648</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>037</adminCode2>
<adminName2>Los Angeles</adminName2>
<adminCode3/><adminName3/>
</code>
</geonames>
= = = = =
Someone provided me with the following but I am not sure how to execute it and parse the variables I need:
<?php
$pc = $_POST['postalcode'];
$c = $_POST['country'];
$xml = file_get_contents("http://ws.geonames.org/postalCodeSearch?postalcode={$pc}&country={$c}");
file_put_contents("geopost_{$pc}_{$c}.xml",$xml);
?>
Thank you for your assistance!
The best thing to do is to see how the XML is structured by navigating directly to the link (I used my own zipcode and country), and then navigate through the tree grabbing the data you need using SimpleXMLElement. This example grabs the Latitude and Longitude:
<?php
$pc = $_POST['postalcode'];
$c = $_POST['country'];
$xml = new SimpleXMLElement(file_get_contents("http://ws.geonames.org/postalCodeSearch?postalcode=".$pc."&country=".$c));
$lat = $xml->code->lat;
$lng = $xml->code->lng;
echo "Lat: $lat<br/>Lng: $lng";
?>
This should help get you started with storing those values.
Step 3 is to process the xml with PHP which is outlined quite nicely with these Simple XML examples
Take a look at PHPs SimpleXML for how to parse and read the XML data received.
I've tried searching google and nothing is clear, plus you guys are way faster and correct.
I have an array as follows:
var bannertext = new Array();
bannertext[1] = "ladidadi";
bannertext[2] = "blahblahblahblah";
bannertext[3] = "oooaaaaooooaaa";
How do I turn the bannertext array into a JSON encoded array so that I can send it to a PHP page and break it down using the json_decode function, and then how do I access the individual variables?
EDIT: Thanks to Gazler for that first part! My PHP page looks like this:
$bannertext = $_GET['bannertext'];
$banner = json_decode($bannertext);
How do I access each of those strings now? LIke echo $banner[1]; and so on?
You use JSON.stringify() however in IE you will need to include the json2 library as IE has no native JSON parsing.
var bannertext = new Array();
bannertext[1] = "ladidadi";
bannertext[2] = "blahblahblahblah";
bannertext[3] = "oooaaaaooooaaa";
console.log(JSON.stringify(bannertext));
As an aside, you can instantiate an array using the array literal syntax.
var bannertext = [];
Here is a blog post explaining the difference.
JSON.stringify:
JSON.stringify(bannertext);
Older browsers, IE7 and below, require an external library Json2 Free CDN
Really stumped on this one.
I have the following PHP file with a variable I am trying to access to place in a dynamic text box on my flash stage.
PHP code:
$returnVars = array();
$returnVars['username'] = "test";
$returnString = http_build_query($returnVars);
//send variables back to Flash
echo $returnString;
AS3 code:
var request:URLRequest = new URLRequest("http://www.mysite.com/flash.php");
request.method = URLRequestMethod.GET;
var loader2:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeHandler);
loader2.dataFormat = URLLoaderDataFormat.VARIABLES;
loader2.load(request);
function completeHandler(event:Event) :void{
var username = event.target.data.username;
// dynamic text box called username
username.text=event.target.data.username;
}
The error:
Error #1009: Cannot access a property
or method of a null object reference.
The code was adapted from a tutorial using a class. However I do not get on with classes so wont be using any.
Any ideas will be most welcome.
-Rob.
When looking at your code, I don't really see anything wrong with the way you are working in AS3 (don't know about Php, but that will be okay too i guess). It's just that you add an eventListener to loader, when you should be adding it to loader2.
And second of all, Why are you naming a variable just the same way as a textBox? that is asking for problems :)
function completeHandler(event:Event) :void{
//Change the variable name of this to something else
var _someOtherVariableName = event.target.data.username;
//dynamic text box called username
username.text = event.target.data.username;
}
The code looks all wrong
First of, are you sure http_build_query is what you need?
Secondly, I'm not an AS veteran, but defining a variable named "username" and then setting it's property "text" in that way looks horribly bad.
Edit: In fact, my observation explains the error. When you define "username", it's obviously not an object. When you try setting the property "text", it won't work for this same reason.
I really think you need to learn the basics of object-oriented programming...
Edit2:
This is the relevant code from the tutorial:
var username = evt.target.data.username;
var email = evt.target.data.email;
trace ('username is ' + username);
trace ('email is ' + email);
As you see, there's no mention of username.text.