tags:

views:

183

answers:

5

I want to print the input value in flex to PHP.

My Flex Code...

<mx:HTTPService id="sendReq" result="google(event)" showBusyCursor="true" method="POST" url="http://localhost/search/index.php" useProxy="false">
     <mx:request xmlns="">
      <keyword>
       {keyword.text}
      </keyword>
     </mx:request>
    </mx:HTTPService>

    <mx:TextInput text="" id="keyword" left="130.5" top="89" right="228.5" height="40" fontSize="20" fontWeight="bold" borderStyle="outset" focusThickness="0"/>

    <mx:Button click="sendReq.send();" id="search" label="search"  right="133.5" top="91" height="40" width="75" alpha="1.0" fillAlphas="[1.0, 1.0]"/>

My PHP code,

$keyword = $_POST['keyword'];
echo $keyword;

But i am not able to receive the keyword from Flex. Can anyone find the error down here which i am not able to get.

+1  A: 

Have you tried using FireBug? it's a firefox extension that can show you exactly what's coming and going on the connection between the flex client and the server.

Dan
excellent, forgot it entirely... Thanks
Actually, it can't. Firebug is awesome, but it is not very effective when trying to get information from what is going on in Flash. I recommend Charles( http://www.charlesproxy.com ) for that (It is one of the best purchases I've made for Flex)
Christopher W. Allen-Poole
@Christopher: I sniff HTTP traffic from my flex app to the server ALL THE TIME. When I'm doing some REST work, it works like a Rolls Royce.
Dan
@Christropher: My code was working fine, i could not trace it and firebug told you are sending the correct request, and getting down the results too just now display it back using event.result
A: 

Check if your request reaches your php script (i.e. log a string on script start). To see what comes to script:

print_r(getallheaders());
print_r($HTTP_RAW_POST_DATA);
print_r($_POST);

Sorry, can't help with flex :(.

Jet
A: 

I would start by writing a php script that accepts the input and emails you or logs to a file, to make sure you have the send-half of the transaction working; then once you're sure that's working, move on to verifying that the expected result is returned.

Adam Tuttle
A: 

In the past when I've used the httpservice I've not set the method parameter (default is 'get')

So i've used something like

<mx:HTTPService id="myCall" 
    url="{'somephp.php'}"
    result="resultHandler(event)" 
    fault="faultHandler(event)"
    showBusyCursor="false" 
    resultFormat="e4x"> 
    <mx:request>
     <somethingToSend>post data inside here</somethingToSend>
        <time>{new Date().getTime()}</time>
    </mx:request>
</mx:HTTPService>

Then inside the php I'd have

$someVarThatsjustComeThrough = $_REQUEST["somethingToSend"];

If whatever you echo back using php, echo it back in an XML format. It will make your job much easier in the flex side to deal with.

Always put the time in, it stops IE from potentially caching the php call.

kenneth
+1  A: 

I don't have time to solve this problem, but here is some advice in debugging it:

First, I would trace everything in the opening tag for your HTTPRequest.

<mx:HTTPService id             = "sendReq" 
                result         = "trace( event )" 
                fault          = "trace( event )" 
                showBusyCursor = "true" 
                method         = "POST" 
                url            = "http://localhost/search/index.php"
                useProxy       = "false">

If there is something wrong with your request, you have absolutely no way of knowing that -- your request has no fault handler!

On the PHP side, the best way to debug an application like this is with some logging system.

Here is a pretty generic logging function:

define( 'PATH_TO_LOG_FOLDER', "../Logs" );

public function log( $message ){
    $logFileName = "log";
 if(!$fp = @fopen(PATH_TO_LOG_FOLDER. DIRECTORY_SEPARATOR . 
    $logFileName .date('Y-m-d').".log", 'a+')){
  return FALSE;
 }

 flock(  $fp, LOCK_EX  ); 
 fwrite( $fp, $message );
 flock(  $fp, LOCK_UN  );
 fclose( $fp );
}

On http://localhost/search/index.php call

$message = "";
for( $_REQUEST as $key => $val )
{
    $message .= "$key = $val\n";
}
log( $message );
Christopher W. Allen-Poole
Majuscule reply mate, i will keep a note of these in my future coding as it can save very handy time.