I am using HTML for the contact form fields and I wish to redirected the inputs to another webpage and have it displayed there. Is there a way to do it with PHP? Thank you!

Dani AI

Generated

For : yes — point the HTML form at a separate PHP page and handle the data there. and already show the basic action/method + echo approach, which is fine for quick tests. For anything beyond a throwaway prototype, add these essentials: check the request method, validate inputs, escape all output to avoid XSS, and use a Post/Redirect/Get flow to prevent duplicate submissions.

A minimal, safer pattern on the display page (do not echo raw input) — check method, validate, then escape when printing:

<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') exit;

$name    = trim((string)($_POST['name'] ?? ''));
$email   = trim((string)($_POST['email'] ?? ''));
$message = trim((string)($_POST['message'] ?? ''));

// simple validation
if ($name === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // handle error (show friendly message or redirect back)
    exit;
}

// escape for HTML output
echo 'Name: ' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . "<br>\n";
echo 'Email: ' . htmlspecialchars($email, ENT_QUOTES, 'UTF-8') . "<br>\n";
echo nl2br(htmlspecialchars($message, ENT_QUOTES, 'UTF-8'));
?>

Use Post/Redirect/Get to avoid browser resubmit and to show the results on a clean URL. Store validated data in session (or database), then redirect to the display page:

// after validation
session_start();
$_SESSION['form_data'] = ['name'=>$name,'email'=>$email,'message'=>$message];
header('Location: display.php');
exit;

On display.php read and unset the session flash data, then escape before printing.

Extra notes: never trust client-side checks alone; use prepared statements (PDO) for DB storage; use a mail library (PHPMailer) instead of raw mail() to avoid header-injection; protect forms with CSRF tokens and serve over HTTPS; sanitize filenames and limit file uploads. ’s example is useful to learn the flow, but avoid outputting user input without the escaping/validation shown above.

Recommended Answers

All 2 Replies

I am using HTML for the contact form fields and I wish to redirected the inputs to another webpage and have it displayed there. Is there a way to do it with PHP? Thank you!

Yes.. You have to use form tag in your html form and specify the action property like

<form method="post" action="secondPage.php">
/* Your html form design here */
</form>

You can display the posted values in secondPage.php

ya you can do this use the following code to do this:-

form.html
<form action="display.php" method="POST">
Name<input type="text" name="u_name" placeholder="enter your name">
//other fields u want to add,add your code here......
</form>

display.php

<?php
echo $_POST['u_name'];
?>

If your problem is solved mark it as solved...

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.