Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, March 29, 2024
About Us
Magazine
Open Source
CVS
Services
Index  »  Projects  »  phpMyEdit  »  Forum  »  Example: automatically set field value(s) in Add View

phpMyEdit General     Example: automatically set field value(s) in Add View
Post new topic   Reply to topic    
 
garyt     Joined: 01 Sep 2007   Posts: 1  
Post Posted: 2007-09-01 21:08
Back to top  Reply with quote     

Very impressed by the script. Want to thank all the authors for their great work.

I have the need to set the values of certain fields in adding a new record. To my understanding,
this is not a standard feature.

I have two tables: 'customers' and 'orders'. The orders table has a field called 'customerID'. Instead of forcing the user to remember and type in the customerID every time when he/she creates a new order, I want to set the field value auotmatically.

Here's my approach:

1. Go to 'orders' listing view, click Add button, and save the HTML source to a new file, i.e, 'AddOrder.php';

2. Locate the line in the 'AddOrder.php' containing 'customerID', replace the default value:

Old code:

Code:
<input class="pme-input-1" type="text" name="PME_data_customerID" size="8" maxlength="8" value="whatever" /></td>

New code:

Code:
<input class="pme-input-1" type="text" name="PME_data_customerID" size="8" maxlength="8" value="<?php echo $_POST['PME_data_customerID']; ?>" /></td>

3. Upload 'AddOrder.php';

4. Make a virtual field in the 'customers' list view:

Code:
$opts['fdd']['virtual_01'] = array(   
  'name'     => 'Action',
  'select'   => 'N',
  'maxlen'   => 10,
  'nowrap'   => true,
  'sort'     => false,
  'options'  => 'L',  // display only in List view

  'URL'      => 'AddOrder.php?PME_data_customerID=$key',

  'sql' => "(select 'Add Order' from customers WHERE ID = PMEtable0.ID)"
);


'ID' is the primary key in the 'customers' table.


Here's what happens:

In the 'customers' list view, we have a virtual field that simply says "Add Order". By clicking it,
the corresponding 'customerID' is passed to the URL, then passed to the 'AddOrder' page, then into the 'PME_data_customerID' form field. URL in your browser should be something like:

http://www.yourdomain.com/yourfolder/AddOrder.php?PME_data_customerID=1234


Gary


     
    Post new topic   Reply to topic    

    Copyright © 2002-2006 Platon Group
    Site powered by Metafox CMS
    Go to Top · Feedback form · Application form
    Report bug on PLATON.SK website · Terms of use · Privacy policy