This topic is locked

Setting fields from other fields...

2/3/2007 7:23:15 PM
PHPRunner General questions
R
run4sbc author

I have PHPRunner 3.1 build 207
From the registration page I have a dropdown menu where the user selects an option such as their school. I want their selection in this option to write data into two other fields TeamCode and TeamName when they click the register button.
Does anyone know how I would do this?
Thanks

T
thesofa 2/3/2007

I have PHPRunner 3.1 build 207

From the registration page I have a dropdown menu where the user selects an option such as their school. I want their selection in this option to write data into two other fields TeamCode and TeamName when they click the register button.
Does anyone know how I would do this?
Thanks



I suggest you download and install the latest version available from this forum.

If you use the custom code event from the Before Registration part of the Registration page, your entered values of the registration details will be held in the $userdata array.

HTH

R
run4sbc author 2/3/2007

Ok, but how would I code it so that if the dropdown item selected is Arkansas it inserts TeamCode ARK and inserts TeamName Arkansas
Selected Item Arkansas

TeamCode = ARK

TeamName = Arkansas
I want it to automatically insert the data automatically based on the dropdown menu.
I just dont have any idea how the code would work, but I know where it would need to go.

T
thesofa 2/3/2007

Ok, but how would I code it so that if the dropdown item selected is Arkansas it inserts TeamCode ARK and inserts TeamName Arkansas

Selected Item Arkansas

TeamCode = ARK

TeamName = Arkansas
I want it to automatically insert the data automatically based on the dropdown menu.
I just dont have any idea how the code would work, but I know where it would need to go.



OK basic process for PHP is identify the data you want to save, in this case it is Arkansas

create a lookup from the table containing the data to get the record.

I assume the table is called _States and the table has a fild of State_code and State_name

so do a 'find *in states where state_name = arkansas

read the data into an array

call the data that you want to save, from the array

make the values of teamcode = array(State_code)

TeamName=array(TeamName).

These values will be written to the table when you click OK

What I would ask you is "do you need to store those values in the table?"

It seems that you have those values in a table already, it would seem wasteful of space and processing cycles to store duplicate data in the database.

In your table of State information, which I assume you use for your drop down lookup box on the Registration page, you have the stateName and TeamCode already stored. Why not add a field of StateID, set as an integer and set to not allow NULL, and set to autoincrement.

This will give you a unique reference to the state in the table.

When you select the state on the reg page, just store the stateID value in the main table.

If you want to display the values in a list, PHPrunner will show the Display Field value from the drop down field anyhow on the list page.

If not, you can always make an inner join from the main table to the states table, and use the value from the sataes table on the list page.
HTH

R
run4sbc author 2/3/2007

Here is the registration page
http://www.trackmeetsonline.com/07IndoorMe...ge/register.php
When you select an item from the dropdown menu under school I want it to then write data into the protection table under the TeamCode and TeamName fields. I want to set the TeamCode and TeamName fields in the coding for them to be stored in the database when the corresponding school from the registration table is selected.
So when they pick a school it saves this data secretly where the user cannot edit it.
So kinda like this.
If school=Arkansas then

savedata TeamCode ARK

savedata TeamName Arkansas
Something like that.

T
thesofa 2/3/2007

Here is the registration page

http://www.trackmeetsonline.com/07IndoorMe...ge/register.php
When you select an item from the dropdown menu under school I want it to then write data into the protection table under the TeamCode and TeamName fields. I want to set the TeamCode and TeamName fields in the coding for them to be stored in the database when the corresponding school from the registration table is selected.
So when they pick a school it saves this data secretly where the user cannot edit it.
So kinda like this.
If school=Arkansas then

savedata TeamCode ARK

savedata TeamName Arkansas
Something like that.

I spose it is a beatiful day in the usa?

It is 1:43 a.m. here in the UK and i have still got some beer to finish.

I have registered on your site as thesofa, I cannot see where I could edit the details!

Sorry but beer is winning tonight

goodnight

R
run4sbc author 2/3/2007

It wasnt a bad day. I spent most of it driving home from New York City. Thanks for the help, I'll work with it some more and see what I come up with.

J
Jane 2/5/2007

Hi,
you can do it using AfterSuccessfulRegistration event on the Events tab.

Here is a sample code:

function AfterSuccessfulRegistration()

{

global $conn,$strTableName;

$str = "select school from ".$strTableName." where Username='".$_SESSION["UserID"]."'";

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

$data = db_fetch_array($rs);
$teamcode = strtoupper(substr($data["school"],0,3));

$strUpdate = "update ".$strTableName." set TeamCode='".$teamcode."', TeamName='".$data["school"]."' where Username='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

}



where Username is your actual field name where user name is stored.

R
run4sbc author 2/5/2007

Thanks Jane. I used the lookup tables and it worked fine. But thanks for the help!!