Jump to content

communicate with php - basic question


erich.wanker

Recommended Posts

hello,

 

Webmode:

 

if i want to show a litte "selfe made grid" - i can user a UniUrlFrame with address:

 

www.mywebserver/myPhp/test.php?value=XY   (the link with the values is generated per delphi-code ...)

 

BUT:

 

if the user clicks on the php-generated grid - how can i get this information back in the uniGui .dll - delphi-code level

 

Ajax is the right thing - i think ;-)  .. but have no ideo what i should do 

 

 

:-)

Link to comment
Share on other sites

Hello zilav, 

thanks for the answer.

 

am i right with:

 

  • url: the "normal" url string and "test.php"
  • value:  my value
  • S_ID:  UniSession.SessionID         (example: 12345)
  • obj: Mainform.UniPanel1.JSName   (example: O123)

 

 

sending to the "test.php"  informations like:

 

  • www.server.com/test.php?value=XYZ&S_ID= +UniSession.SessionID + %obj= Mainform.UniPanel1.JSName

 

 

 

uniPanel1.onAjaxEvent:

procedure TMainForm.unipanel1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TStrings);
begin
  showmessage(' the clicked cell is: ' + ????? );
end;

 

 

the test.php - html Output :

<div align="left">
  <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="101" height="39">
    <tr>
      <td width="44" height="17"><a href="http://www.server.com/...value=cell1..?...">cell1</a></td>
      <td width="51" height="17"><a href="http://www.server.com/...value=cell2..?...">cell2</a></td>
    </tr>
    <tr>
      <td width="44" height="18"><a href="http://www.server.com/...value=cell3..?...">cell3</a></td>
      <td width="51" height="18"><a href="http://www.server.com/...value=cell4..?...">cell4</a></td>
    </tr>
  </table>
</div>

BUT: 

 

what is the right  href - definition and the "uniPanel1.onAjaxEvent -delphicode"   to fire the "showmessage cellnumber of uniPanle1" ?

 

Thanks for helping :-)

Link to comment
Share on other sites

The main problem here is cross domain ajax since url inside UniHTMFrame is essentially an IFRAME from different domain. Grabbing a clicked value will work only once if using ordinary href, after that frame will be cleared.

I really recommend you to generate your table inside uniGUI application instead of external php script and put in into TUniHTMLFrame with native uni's ajaxRequest calls.

Or get html code from php script with http request and again put it into TUniHTMLFrame.

Link to comment
Share on other sites

:-) Thanks again ...

 

 

ok .. i can  get the html code from php script with "http request" and put it into TuniHTMLFrame .. 

 

but what must i do to activate a "showmessage procedure with values" from the php generated stuff ?

 

As example:

 

if i click in "cell 1" from the php generated table what is showen in a TUniHtmlFrame

- i want to make a showmessage (in UniGUI delphi-code) with output of the cell-Integer ? 

 

 

.. i dont understand how to communicate between uniGui-delphi-code  and the php-generated HTML Stuff :-(

 

Thanks for helping

Link to comment
Share on other sites

You have 4 alternatives:

 

(1) UniHtmlFrame

Your HTML code is now part of the UniGui. You can use javascript on click to send a message to the server: ajaxRequest(...)

 

(2) UniUrlFrame (iframe), if server and port are the same

You can access the iframe from UniGui html page and vice versa using javascript

 

(3) UniUrlFrame (iframe), if server and/or port are different

Alternative (2) doesn't work. But you can change the url (parameters) of the iframe and on change of the url do something

 

(4) completely independent

See my project "MessageServer"

With this it is even possible to click on the php site on one pc and show the message on another pc in unigui (sure iframe also possible).

Link to comment
Share on other sites

thanX for Information..

 

..aber irgendwie steh ich noch auf der Leitung...

 

BUT: ;-)

 

Now i have:

 

1 x UniSyntaxEdit1

1 x UniHTMLFrame1

1 x uniButton1

 

 

i can load or write javascript and html code in the UniSyntaxEdit1

i can "load" it: UniHTMLFrame1.HTML.Text:=UniSyntaxEdit1.Text;

 

-> as a example: the UniHTMLFrame1 displays a tabel with customers - a css file changes the row-color : on mouseover, onMouseExit, onClick ...

 

What must i do to get the clicked customer into delphi - to validate, calculate or manipulate the informations with delphi code ? .. i dont have good experiance with javascript 

 

 

i am searching somthing like:

every row of the html table has a individual information like:   href="www.server.com/uniGui.dll?sender=theHtmlTable1&record_nr=123&record_name=Smith"

and the uniGui Mainform or somthing has a "here comes a information"- event where i can grab the values ... and do with delphi what i want with this values ?

 

i am not understanding - how i can send informations from the html into delphi (and the thing should not refresh a page, just while i clicked something ..)

 

Thanks for helping

 

;-)

Link to comment
Share on other sites

If you have a html table you must add a javascript onclick event to a row or a cell:

<table>
<tbody>
<tr onclick="alert('record number 1')">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr onclick="alert('record number 2')">
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr onclick="alert('record number 3')">
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tbody>
</table>
<p> </p>

But instead using alert() in example you must use ajaxRequest(...) (see forum) and then you can use the onAjaxRequest event on server side to catch the message.

Link to comment
Share on other sites

it works ... PERFECT :excl:

 

<tr onclick='ajaxRequest(MainForm.form,"EsGehtLos" , [ "Parameter01=02" , "Parameter02=02" ]);'>

 

and for components in a frame:

<tr onclick='ajaxRequest(framename.component_name,"EsGehtLos" , [ "Parameter01=02" , "Parameter02=02" ]);'>

 

 

many thanks for helping !!!!

 

:D

 

 

 

 

P.S.:

procedure Tmodul001_frame_detail1.UniMemo1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TStrings);
  var i:Integer;
begin
unimemo1.Lines.Append(EventName);
for i:=0 to Params.Count-1 do
  begin
   unimemo1.Lines.Append(Params[i]);
  end;


end;
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...