hi all,

Can I use a variable from a .php file to give a value to an HTML FormMail form field thus:? please reply soon.

Thanks
-----------------------<URL SNIPPED>

Dani AI

Generated

Short answer: yes — the PHP that generates the page can fill form fields before the browser sees them. was right to reply quickly and pointed in the right direction; below are practical, safe steps to do that and avoid common pitfalls you might see years later when someone views the page.

Always escape output and provide safe defaults so special characters or missing values do not break HTML or create XSS issues. For text fields and textarea use htmlspecialchars with ENT_QUOTES and an explicit charset. Prefer validating or casting numeric inputs. If the value must travel between pages (or into a third‑party FormMail handler), use a hidden field or a session and make sure the handler expects that field name. Never place unvalidated user input into mail headers. Example patterns:

<?php
$name = isset($_GET['name']) ? $_GET['name'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
?>
<input type="text" name="name" value="<?php echo htmlspecialchars($name, ENT_QUOTES, 'UTF-8'); ?>">

<textarea name="message"><?php echo htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); ?></textarea>

Further reading on safe output escaping: htmlspecialchars - PHP Manual and the .

Recommended Answers

All 3 Replies

yes

See here.

When printing the form, just put the PHP variable in the "value" attribute of the input field.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.