Hi All,
I am trying to work out a method to add entry’s thru a flash form. I was thinking to use the safecracker module but I can’t figure out if it’s possible to submit post data thru safecracker without using a default form.
I have tried the following:
(as3) Just post some data to the server.
var variables:URLVariables = new URLVariables();
variables.title = 'Via Flash';
variables.field_id_1 = 'Cras gravida, diam sit amet rhoncus ornare, erat elit consectetuer erat, id egestas pede nibh eget odio.';
var request:URLRequest = new URLRequest("http://localhost/ee2_1_5_testomgeving/index.php/post/post/");
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.load( request );
loader.addEventListener(Event.COMPLETE, this.loaderComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, this.loaderError);
this.ai.width = 600;
this.ai.height = 400;
this.ai.color = 0xFF0000;
this.ai.alpha = 1;
this.textBox = new Asset(this.ai);
this.textBox.x = this.textBox.y = ((GlobalStage.stageInstance.stageWidth / 2) - (this.textBox.visibleWidth / 2));
this.addChild(this.textBox);(php ee) Simply use the api to post the info to a channe. This was merely a test and not made to actually use. This requires login to EE or it won’t work.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$plugin_info = array(
'pi_name' => 'Custom Post Data',
'pi_version' => '0.1',
'pi_author' => 'Dion Snoeijen',
'pi_author_url' => 'http://www.apsbb.com/',
'pi_description' => 'Post Custom Data',
'pi_usage' => Custom_post_data::usage()
);
class Custom_post_data
{
public $return_data = '';
public function Custom_post_data()
{
$this->EE =& get_instance();
$this->EE->load->library('api');
$this->EE->api->instantiate('channel_entries');
$title = $_POST['title'];
$field_id_1 = $_POST['field_id_1'];
echo $title . '
';
//echo $time = time();
echo $field_id_1;
$data = array(
'title' => $title,
'entry_date' => time(),
'field_id_1' => $field_id_1,
'field_ft_1' => 'none'
);
if ($this->EE->api_channel_entries->submit_new_entry(1, $data) === FALSE)
{
show_error('An Error Occurred Creating the Entry');
}
return $this->return_data;
}
public function usage()
{
ob_start();
?>
Post any sort of data to server and execute extension command
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
}So now I am thinking to use Safecracker but I am not even sure if it’s possible to approach that in a similar way, or if it’s even possible at all? Maybe someone can give me a slight bump in the right direction, I have only made a couple of simple pi’s for EE so I am not overly familliar with the ins and outs of developing for EE.
Thanks!
Sure. I still have an unsolvable problem in that EE (correctly) returns 302 redirects that the FLash Player can’t follow: http://ellislab.com/forums/viewthread/197338/
I did find a couple, much better solutions though. One was doing as suggested in the thread above - using the Metaweblog API. This does the trick for now that I only need to store text strings. If I need something more advanced, I’ll use AMFie: http://devot-ee.com/add-ons/amfie/
J
Here’s the code snippet I use with the Metaweblog API:
/**
* Stores the users progression
* Uses the Metaweblog API module in ExpressionEngine
*
* @param session_id The id returned from getSession();
* @param key A key you define for use with your application
* @param value A value for the key
*
*/
public static function saveContent( session_id:String, key:String, value:String ):void
{
// The message that the MetaWeblog API wants
var payload:String = "";
payload += "<methodCall>";
payload += " <methodName>metaWeblog.newPost</methodName>";
payload += " ";
payload += " ";
payload += " <value><i4>2</i4></value>"; // EE channel
payload += " </param>";
payload += " ";
payload += " <value>myuser</value>"; // EE user
payload += " </param>";
payload += " ";
payload += " <value>mypass</value>"; // EE password
payload += " </param>";
payload += " ";
payload += " <value>";
payload += " <struct>"; // Struct with members per field
payload += " <member>";
payload += " <name>title</name>";
payload += " <value>"+session_id+" - "+key+" - "+value+"</value>";
payload += " </member>";
payload += " <member>";
payload += " <name>mt_excerpt</name>";
payload += " <value>"+session_id+"</value>";
payload += " </member>";
payload += " <member>";
payload += " <name>description</name>";
payload += " <value>"+key+"</value>";
payload += " </member>";
payload += " <member>";
payload += " <name>mt_text_more</name>";
payload += " <value>"+value+"</value>";
payload += " </member>";
payload += " <member>";
payload += " <name>mt_keywords</name>";
payload += " <value>mt_keywords</value>";
payload += " </member>";
payload += " </struct>";
payload += " </value>";
payload += " </param>";
payload += " ";
payload += " <value><i4>1</i4></value>";
payload += " </param>";
payload += " </params>";
payload += "</methodCall>";
var req:URLRequest = new URLRequest("http://example.com/?ACT=45&id=1"); // This value, you'll find on EE's metaweblog api module info page
req.method = URLRequestMethod.POST;
req.data = payload;
// Flash will add User-Agent and Content-Length for us, but Content-Type we set ourselves
var contentType:URLRequestHeader = new URLRequestHeader("Content-Type", "text/xml");
req.requestHeaders.push(contentType);
xml_request = new URLLoader();
xml_request.addEventListener( Event.COMPLETE, saveContentResult );
xml_request.addEventListener( IOErrorEvent.IO_ERROR, error );
xml_request.addEventListener( HTTPStatusEvent.HTTP_STATUS, httpResponse );
xml_request.load(req);
}session_id, key and value contain the stuff I need to save.
J
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.