This topic is locked
[SOLVED]

 Button redirect

5/5/2016 9:06:37 PM
PHPRunner General questions
C
cjsaputo author

I have added a button to the grid of a list screen. I want the button to redirect to an add screen for a related table and pass three fields.
Any help would be appreciated.

Sergey Kornilov admin 5/6/2016

It doesn't have to be a button, can be just a link like tablename_add.php?field1=someval1&field2=someval2&field3=someval3

Then on the Add page you can use $_GET["field1"] as a default value for one of those fields.
To build such a link you can use 'View as' Custom, here is the sample code:

$value = "<a href='tablename_add.php?field1='".$data["field1"] . "'>Add new</a>";
C
cjsaputo author 5/9/2016

I have inserted a field at the end of the record line on the list screen with the following custom code:

$value = "<a href='donors_add.php?fname='".$data["first_name"]."'>Donation</a>";
I also added the following to the donors_add screen in the first name field under Default value:

$_GET["fname"]
When I click the Donation text/link on the members list screen it does open the donors add screen but the first name is blank.
I also want to pass the field values last_name and donorid, but I am not sure of the syntax for adding these to the $value command.
Thanks in advance.



It doesn't have to be a button, can be just a link like tablename_add.php?field1=someval1&field2=someval2&field3=someval3

Then on the Add page you can use $_GET["field1"] as a default value for one of those fields.
To build such a link you can use 'View as' Custom, here is the sample code:

$value = "<a href='tablename_add.php?field1='".$data["field1"] . "'>Add new</a>";


lefty 5/11/2016



I have inserted a field at the end of the record line on the list screen with the following custom code:

$value = "<a href='donors_add.php?fname='".$data["first_name"]."'>Donation</a>";
I also added the following to the donors_add screen in the first name field under Default value:

$_GET["fname"]
When I click the Donation text/link on the members list screen it does open the donors add screen but the first name is blank.
I also want to pass the field values last_name and donorid, but I am not sure of the syntax for adding these to the $value command.
Thanks in advance.


$value = "<a href='tablename_add.php?field1=".$data["first_name"]."&field2=".$data["last_name"]."&field3=".$data["donorid"]."'>Add New</a>";

be careful not to miss the single ' at the end before link. I thought you would need single quotes wrapped for each field since they were text fields but did not work for me but the above sample worked. field1 , field2, field3 are the field names in the Add page table.
Default Value on Add Pages $GET["field1"] etc.....

C
cjsaputo author 5/21/2016

I have made the changes and all of this is now working. First, thanks very much for the help. Second, after further testing I have realized a few design flaws and would like to see if anyone has a solution. As before, I will probably need code samples since I am not a coder.

  1. Two tables; members and donors.
  2. Members can have more than one donor record.
  3. Both tables contain a field donorid, which is used to relate the records.
  4. The link I have added on the member list screen works to open the donor add screen.
  5. When the member record already has a donor record, the donor add screen fields of donorid, first_name and last_name are properly filled from the member record.
  6. When the member record does not have a donor record(this is the first time the member has donated), the donorid field in the member table is blank(as it should be).
  7. In order to solve the issue of creating a first time donor record with a unique donorid I created a single field control table with a numeric field and set the value to the next highest donorid.
    Problem #1: I added this code to the member list screen when the donation link is clicked;

    $value = "<a href='donors_add.php?first_name=".$data["first_name"]."&last_name=".$data["last_name"]."&donorid=".$data["donorid1"]."&id1=".$data["id"]."'>Donation</a>";

    This works for all fields when a donation record already exists.

    I added the following code to the donoird field of the donation add screen; $_GET["donorid"];

    IF (empty($donorid)) $donorid=$id1;

    My goal here is to populate the donorid field from the control table if the donorid field in the member record is blank. This is not working.
    Problem #2: After saving the donation record for a first time donor I need to increment the value of the id field in the control table. I have to make sure that this is only done for a first time donor. Not sure how to differentiate this in the "After record added" Event, if that is where it should be done.
    Problem #3: I would like to make the donation add screen a popup window over the member list screen so that this window closes on save and returns to the member list screen. There must be a way to modify the call of the donors_add.php above to accomplish this.


    $value = "<a href='tablename_add.php?field1=".$data["first_name"]."&field2=".$data["last_name"]."&field3=".$data["donorid"]."'>Add New</a>";

    be careful not to miss the single ' at the end before link. I thought you would need single quotes wrapped for each field since they were text fields but did not work for me but the above sample worked. field1 , field2, field3 are the field names in the Add page table.
    Default Value on Add Pages $GET["field1"] etc.....