Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Passing Tokens with PHP

Featured Replies

Hi, I'm used to using tokens with FM 5.5.  What's the best way to pass a field variable thru a form with PHP?  I have a 'club number' field that is auto-entered for the head of a club.  I'd like to pass that field variable thru via a form to a new input form that will give new users that club number thru a hidden input.

 

Thanks!

Is it a field or a variable? It can't be both.

The PHP API is layout driven.  Since there is no way to put a variable on a layout*, you have to use a field. 

Simply use a

$clubnum = $result->getField('ClubNumField'); 

statement at the beginning of your PHP script, and in the HTML input statement, use

value="<?php echo $clubnum ?>"

  If the second form is in a different PHP script, set a $_SESSION[] variable in the original script, and pick it up in the subscript.

 

*Except, of course, as a merge variable in a text object, but the PHP API can't access that, either. 

  • Author

Thanks Doughemi, I want to pass the variable from the field 'clubnumber' from one form on one page to a new input form on another page.  How do I send that thru on the original form? 

<form action="InsertRecord.php?clubnumber=<?php echo $_GET['clubnumber']; ?>" method="post">

or
    <input type="hidden" name="clubnumber" value="<?php echo $_GET['clubnumber']; ?>">

Also, after submitting, I'd like all info from a new input form to be passed thru to an edit form, is it the same technique?  I know how to do all this in CDML, but I'm trying to find out in PHP.

 

Thanks!

There are a number of ways to do this, but to find the best one requires a more detailed description of the workflow.

Are all the (two? three? four?) forms presented to the user in one session?

Why are there (two? three? four?) forms to begin with? 

Please describe the sequence of events from the perspective of the user.

  • Author

Here's what I'm trying to re-create from filemaker 5.5 with FMP 12 and PHP.  Here is a login page.  

http://tutsan.forest.net/ssv/FMPro?-db=ssvdb.fp5&-lay=master&-format=loginpro.html&-op=eq&pro=y&-view

Put 'clubnumber' 6580 and 'propassword' johnson.  A button is create to go to 'New Club Pro Page'.  From there, the hidden input of clubnumber 6580 and club name of 'New Club' is passed by CDML tokens and added to a new record when you 'add new player'.   

Feel free to add a fictious name.  After submitting, it goes to a results page with other options.  On the pro page, when you refresh the page, or 'see all records', your new record is added.

I'm sure there's a simpler way.  Thanks for all your help!  Attached are the login page, pro page, new record page and result page.

loginpro.html

newinput.html

newinputreply.html

results.html

Pass the tokens as $_SESSION[] variables. As the name implies, $_SESSION[] variables are stored for the duration of the session. See http://php.net/manual/en/reserved.variables.session.php

Place this code at the beginning of your login page

<?php
session_start;
if(isset $_POST['-find']){
$_SESSION['clubnumber'] = $_POST['clubnumber'];
//Set other $_SESSION[] values as required
header('location:newinput.html');
}
?>

 

header() will not work if any html has been sent to the browser, so this code must be at the very beginning.

The action for this form will be the current file.

The line session_start; must begin the first php code in any script that uses the $_SESSION[] variables.

In newinput.html, the hidden input would look like

<input type="hidden" name="clubnumber" value="<?php echo $_SESSION['clubnumber']">

Each page with a form that requires passing variables to another page would contain similar structure.

  • Author

Thanks again Doughemi, I didn't use Sessions, I was actually able to pass variables thru URL like:

echo '<a href="newinput.php?clubnumber=' . $record->getField('clubnumber') . '&Club=' . $record->getField('Club') . '"></a>';

 

and then retrieve them:

 

<input name="clubnumber" type="hidden" value="<?php echo $_GET['clubnumber']; ?>" />
    <input name="Club" type="hidden" value="<?php echo $_GET['Club']; ?>" />

 

How can I put a number in front of any array like:

1

2

3

4

in CDML it's [FMP-currentRecord Number]

 

Thanks Again!

 


   

Increment a $i variable for each run of the foreach used to create the list?

 

Cheers


Webko

  • Author

Thanks Webko, that sounds right.  I'm just getting started with PHP, can you give me an idea what that would look like?

In pseudo-code, it might be like

{?php
//Do some find
$i = 1;
foreach {
    //The loop that creastes the list...
    echo $i;
    echo " ";
    echo $someDataFromTheArray;
}
?>

 

  • Author

Thanks Webko, I didn't understand the

echo " ";

does that help create a numbered list?

Thanks!

 

It just puts a space between the number and the list items...

I also forgot to increment the counter for each row - $i++;

But that was demonstrated in the answers to your later post

Cheers

Webko

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.