I have an input form with several fields. What I would like to achieve is to auto populate or copy certain fields if they are empty when the form is submitted. I would like to use php if not then javascript but not jquery if possible - I have sort of had a go but I really have no idea
The bit of logic I need is:
If rNradd is empty then do nothing;
If rNradd and rVprism contain data and rNrVprism is empty then copy rVprism to rNrVprism;
If rNrVprism already contains data then do nothing.
There are a few other fields I need to do this for at the same time so I need the solution to be expandable.
Here is the section of code in question (written in DW - please do not be too derogatory):
$insertSQL = sprintf("INSERT INTO spec_rx (spec_rx_id, FK_px_id, spec_rx_date, FK_user_id, spec_rx_rsph, spec_rx_rcyl, spec_rx_raxis, spec_rx_rhprism, spec_rx_rhprismbase, spec_rx_rvprism, spec_rx_rvprismbase, spec_rx_rnadd, spec_rx_rnhprism, spec_rx_rnhprismbase, spec_rx_rnvprism, spec_rx_rnvprismbase, spec_rx_rintadd, spec_rx_rinthprism, spec_rx_rinthprismbase, spec_rx_rintvprism, spec_rx_rintvprismbase, spec_rx_lsph, spec_rx_lcyl, spec_rx_laxis, spec_rx_lhprism, spec_rx_lhprismbase, spec_rx_lvprism, spec_rx_lvprismbase, spec_rx_lintadd, spec_rx_linthprism, spec_rx_linthprismbase, spec_rx_lintvprism, spec_rx_lintvprismbase, spec_rx_lnadd, spec_rx_lnhprism, spec_rx_lnhprismbase, spec_rx_lnvprism, spec_rx_lnvprismbase, ext_rx) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['SpecRxID'], "int"),
GetSQLValueString($_POST['pxID'], "int"),
GetSQLValueString($_POST['specRxDate'], "date"),
GetSQLValueString($_POST['userID'], "int"),
GetSQLValueString($_POST['rsph'], "double"),
GetSQLValueString($_POST['rcyl'], "double"),
GetSQLValueString($_POST['raxis'], "double"),
GetSQLValueString($_POST['rHprism'], "double"),
GetSQLValueString($_POST['rHprismbase'], "text"),
GetSQLValueString($_POST['rVprism'], "double"),
GetSQLValueString($_POST['rVprismbase'], "text"),
GetSQLValueString($_POST['rNradd'], "double"),
GetSQLValueString($_POST['rNrHprism'], "double"),
GetSQLValueString($_POST['rNrHprismbase'], "text"),
GetSQLValueString($_POST['rNrVprism'], "double"),
I have tried to add the following code without success:
extract ($_POST);
if (empty($_POST['$rNrVprism']) && !empty($_POST['$rNradd']) && !empty($_POST['$rVprism'])){
$_POST['$rNrVprism'] = '$rVprism';
}
I would really be grateful for some help