$stock) { if ($stock['stock'] === $symbol) { $stockIndex = $index; break; } } if ($stockIndex === null && !empty($symbol)) { $message = "Stock '$symbol' not found in your portfolio."; $messageType = 'error'; } $currentIsin = ''; $currentNrbght = ''; $currentDepot = 'scalablecapital'; // Default value $currentPricetarget = ''; if ($stockIndex !== null) { $currentIsin = $stocks[$stockIndex]['isin'] ?? ''; $currentNrbght = $stocks[$stockIndex]['nrbght'] ?? ''; $currentDepot = $stocks[$stockIndex]['depot'] ?? 'scalablecapital'; $currentPricetarget = $stocks[$stockIndex]['pricetarget'] ?? ''; } if ($_SERVER['REQUEST_METHOD'] === 'POST' && $stockIndex !== null) { $isin = isset($_POST['isin']) ? strtoupper(trim($_POST['isin'])) : ''; $nrbght = isset($_POST['nrbght']) ? trim($_POST['nrbght']) : ''; $depot = isset($_POST['depot']) ? trim($_POST['depot']) : 'scalablecapital'; $pricetarget = isset($_POST['pricetarget']) ? trim($_POST['pricetarget']) : ''; $errors = []; if (empty($isin)) { $errors[] = 'ISIN code is required.'; } elseif (!preg_match('/^[A-Z]{2}[A-Z0-9]{9}[0-9]$/', $isin)) { $errors[] = 'Invalid ISIN format. ISIN must be 12 characters: 2 letters, 9 alphanumeric, 1 check digit.'; } if (empty($nrbght)) { $errors[] = 'Number bought is required.'; } elseif (!is_numeric($nrbght) || $nrbght <= 0 || floor($nrbght) != $nrbght) { $errors[] = 'Number bought must be a positive whole number.'; } if (!in_array($depot, ['scalablecapital', 'ingdiba', 'comdirect'])) { $errors[] = 'Invalid depot selection.'; } // pricetarget is optional - only validate if the user actually filled it in if ($pricetarget !== '' && !is_numeric($pricetarget)) { $errors[] = 'Price target must be a number.'; } if (empty($errors)) { $stocks[$stockIndex]['isin'] = $isin; $stocks[$stockIndex]['nrbght'] = (int)$nrbght; $stocks[$stockIndex]['depot'] = $depot; // Only add/update "pricetarget" in the JSON if the user filled it in. // If left empty, behaviour stays exactly as it is now (field untouched). if ($pricetarget !== '') { $stocks[$stockIndex]['pricetarget'] = (float)$pricetarget; } saveStocks($stocks); $message = "Successfully added ISIN: $isin, Quantity: $nrbght, and Depot: $depot for $symbol."; if ($pricetarget !== '') { $message .= " Price target: $pricetarget."; } $messageType = 'success'; $currentIsin = $isin; $currentNrbght = $nrbght; $currentDepot = $depot; if ($pricetarget !== '') { $currentPricetarget = $pricetarget; } } else { $message = implode('
', $errors); $messageType = 'error'; } } ?> Buy Stock - Add ISIN, Quantity & Depot

?? Add Stock Details

Enter ISIN, quantity purchased & depot

Stock '' was not found in your portfolio.

? Go back
Please provide a stock symbol: buy.php?go=AAPL

?? Currently Saved

ISIN: Not set'; ?>
Quantity Bought: Not set'; ?>
Depot: Not set'; ?>
Price Target: Not set'; ?>
International Securities Identification Number (12 characters: 2 letters + 9 alphanumeric + 1 check digit)
Total quantity of shares purchased
Select the depot/broker where this stock is held
Leave empty to skip. If filled in, it will be saved as "pricetarget" in the JSON.
? Cancel

?? What happens next?
The ISIN, quantity, and depot will be saved directly to stocks.json under the entry for . These fields are stored as "isin", "nrbght", and "depot". If you fill in a price target, it will also be saved as "pricetarget".