This topic is locked
[SOLVED]

 Using data from Add/Edit pages

4/14/2010 1:19:48 PM
PHPRunner General questions
ficcionista author

Hi, to put it simple, what I need is to allow the user to send some of the fields on the Add or Edit page to another app.
I have a MySQL DB receiving data from an external database, using SOAP/Webservice.

I also have another SOAP function to insert comments in the external DB.
I have a table named comments, with the following fields:
'username',

'reportID',

'comment',

'timestamp'
What i need to do is create a button that stores both 'reportID' and 'comment' fields into two php variables in order for me to be able to the Webservice provided to insert comments into the external database.
I've been trying to do this with the "Add new button" feature, but without success so far.
Can anyone help me out?
Many thanks

Sergey Kornilov admin 4/14/2010

I would suggest to store field values in session variables using BeforeDisplay or BeforeProcess events.
Then you can add a button using 'Insert Button' feature and write PHP code in 'OnServer' section that sends data to your web service.

ficcionista author 4/14/2010

I was just thinking about that...
Thanks, I'll try it tomorrow and post my findings here. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=49159&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

ficcionista author 4/19/2010

Well, I've tried many ways to store session variables, 'before process' and 'before add' but I am still unable to store the comment variable

  • 'username' - I have stored in $_SESSION["userid"].
  • 'reportID' - I'm using: $_SESSION["<tablename>_masterkey1"]
  • 'comment' - I'm unable to store. (This is a text field)

Of course I'll keep trying, but in the meantime if anyone has any ideas they'll be more than welcome..

Sergey Kornilov admin 4/19/2010

ficc,
you are not 'storing' values in session variables. You rather use what's been stored already.
In BeforeProcess event you need to execute a SQL query that retrieves data from the database and then store this data in session variables. We are talking about the edit page of course as Add page doesn't have any data yet.
Example (replace what's in bold with actual table/field names):



global $dal;

$rs = $dal->Table("YourTable")->Query("KeyColumn=" . $_REQUEST["editid1"],"");

$data = db_fetch_array($rs);

$_SESSION["reportID"] = $data["reportID"];

ficcionista author 4/20/2010

Thanks Sergey, I've allready come to that conclusion.
Here's what i've done to make it work:
I only need four pieces of information for the webservice:
Username and Password, both "constants". They are unrelated to the app i'm building with PHPR and belong to the webservice alone.

reportID - the index field used by the webservice to associate the comment with a given ticket.

comentario - The comment to be associated.
In Visual Editor of the Edit Page I've created a button opening up a new page where my Webservice is configured:

$button_name="Send Comment"; //Change this to whatever you want the button text to say...
echo ("<SPAN class=buttonborder><INPUT class=button type=reset value=\"".$button_name."\"

onclick=\"window.open('sabao_comments.php','Resultado','resizable=no,width=500,height=400, top=10, left=10')\"></SPAN>");


Then on BeforeProcessEdit event I populated the variables I needed:

global $conn;

$strSQL = "select commentID, comentario from comentariosnf where commentID=".$_REQUEST["editid1"];

$rs = db_query($strSQL,$conn);

$data=db_fetch_array($rs);
$_SESSION["comentario"] = $data["comentario"];

$_SESSION["commentID"] = $data["commentID"];


I also have a field with a 1 or 0 option in my table that informs the user if the comment has been sent to the webservice or not. That's why i need the "commentID" field.