randyinla Posted September 22, 2015 Posted September 22, 2015 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!
doughemi Posted September 22, 2015 Posted September 22, 2015 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.
randyinla Posted September 23, 2015 Author Posted September 23, 2015 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!
doughemi Posted September 23, 2015 Posted September 23, 2015 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.
randyinla Posted September 24, 2015 Author Posted September 24, 2015 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
doughemi Posted September 24, 2015 Posted September 24, 2015 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.
randyinla Posted September 25, 2015 Author Posted September 25, 2015 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!
webko Posted September 28, 2015 Posted September 28, 2015 Increment a $i variable for each run of the foreach used to create the list? Cheers Webko
randyinla Posted September 28, 2015 Author Posted September 28, 2015 Thanks Webko, that sounds right. I'm just getting started with PHP, can you give me an idea what that would look like?
webko Posted October 1, 2015 Posted October 1, 2015 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; } ?>
randyinla Posted October 1, 2015 Author Posted October 1, 2015 Thanks Webko, I didn't understand the echo " "; does that help create a numbered list? Thanks!
webko Posted October 1, 2015 Posted October 1, 2015 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 1
Recommended Posts
This topic is 3596 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now