Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Example: automatically set field value(s) in Add View

phpMyEdit General     Example: automatically set field value(s) in Add View
Odoslať novú tému   Odpovedať na tému    
 
garyt     Založený: 01.09.2007   Príspevky: 1  
Príspevok Zaslal: 2007-09-01 21:08
Návrat hore  Odpovedať s citátom     

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:

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

New code:

Kód:
<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:

Kód:
$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


     
    Odoslať novú tému   Odpovedať na tému    

    Copyright © 2002-2006 Platon Group
    Stránka používa redakčný systém Metafox
    Na začiatok · Odkazový formulár · Prihláška
    Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov