What potential pitfalls should be considered when designing PHP forms that involve calculations and user input retention?

One potential pitfall when designing PHP forms that involve calculations and user input retention is the risk of security vulnerabilities such as injection attacks. To mitigate this risk, it is important to sanitize and validate user input before using it in calculations or storing it in the database.

// Sanitize and validate user input before using it in calculations
$input_value = isset($_POST['input_value']) ? filter_var($_POST['input_value'], FILTER_SANITIZE_NUMBER_INT) : 0;

// Perform calculations using the sanitized input value
$result = $input_value * 2;

// Retain user input in the form
<input type="text" name="input_value" value="<?php echo $input_value; ?>">