This topic is locked

Radio Button with List of Values

2/6/2009 2:44:32 AM
PHPRunner General questions
J
jdu001 author

Problem:
I use PHPrunner 5.0 with a MySQL database.

In the database I have a field defined: approved, TINYINT, length 1, NOT NULL, DEFAULT 1
On the ADD/EDIT screen I want for this field two radio buttons which are labeled Yes and No.
In the visual editor in the properties screen for this field I selected "Radio button", Selected "List of values", entered "Default value" 1

Whith the + butten I added the values No and Yes.
When I build the project, I choose Add, I see two buttons, labeled No and Yes and the Yes-button is selected. I save the created record.

I then edit the created record. No Radio Button is selected. When I look in the databese the value has changed to zero.
What do I wrong ?

J
Jane 2/6/2009

Jo,
check selected values in the Before record added/Before record updated events on the Events tab and save correct numeric value (1 or 0) in the database.

Here is a sample:

if ($value["FieldName"]=="Yes")

$value["FieldName"] = 1;

else

$value["FieldName"] = 0;

J
jdu001 author 3/17/2009

Hello Jane,
This works good, however every time I enter the edit-screen, the 'Yes'-button is activated.
The database-values 0 and 1 have to be translated into 'No' and 'Yes'. I have tried to accomplish this with custom code in an before display event on the edit screen.

I can't get it working.

  1. Can I in the before display event refer to the database-variables ?
  2. How can I change these values before displaying them ?
    Can you help me

J
Jane 3/17/2009

Hi,
use Edit page: Before display event to transate values from database to your values.

Here is a sample:

global $control_FieldName;

if ($control_FieldName["params"]["value"]==0)

if ($control_FieldName["params"]["value"] = "No";

else

if ($control_FieldName["params"]["value"] = "Yes";

J
jdu001 author 3/17/2009

Hi,
I have your code implemented in the after display event. However the value doesn't change. Once the value is "Yes" it stays "Yes".
I put some echo's in the code. This is what happened:
In the list-page is the checkbox for a record selected.

I select this record for edit:

Before Display: Yes

After Display: Yes
The radiobutton "Yes" is activated. I select the radiobutton "No" en push the button "Save":

Before update:No

After update:0

Before Display: Yes

After Display: Yes
When I return to the list-page, the checkbox is not selected. However the value in the database is updated.
Here is the code I used.
Before display event:
global $control_InclusiefDirectie;

echo "<p>"."Before Display: ".$control_InclusiefDirectie["params"]["value"]."</p>";

if (($control_InclusiefDirectie["params"]["value"]=="Yes")||($control_InclusiefDirectie["params"]["value"]==1))

$control_InclusiefDirectie["params"]["value"] = "Yes";

else

$control_InclusiefDirectie["params"]["value"] = "No";

echo "<p>"."After Display: ".$control_InclusiefDirectie["params"]["value"]."</p>";
Before record updated event:
echo "<p>"."Before update:".$values["InclusiefDirectie"]."<p>";

if ($values["InclusiefDirectie"]=="Yes")

$values["InclusiefDirectie"] = 1;

else

$values["InclusiefDirectie"] = 0;

echo "<p>"."After update:".$values["InclusiefDirectie"]."<p>";
Thanks for your assistance.
Jo van Duin

J
Jane 3/18/2009

Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.