Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Refresher

Featured Replies

Hiya one & all. Ive been away from php etc for a while due to looking after an ill family member. I never got time to really delve into what i really love (ie coding) as didnt have the time. Hope to do so from now on.

 

Briefly i typed the following & returned the next following. Can u plz advise why?

 

I am looking to learn.

 

Thankyou

 

 

<!Doctype html>

<html>

<head>

<title>Form Feedback</title>

</head>

<body>

<?php # Script 2.2 - handle_form.php

 

// Create a shorthand for the form data.

$name = $_REQUEST['name'];

$email = $_REQUEST['email'];

$comments = $_REQUEST['comments'];

// Not used: $_REQUEST['age'],

// $_REQUEST['gender'], and

// $_REQUEST['submit'].

 

// Print the submitted information.

echo "<p>Thank you, <b>$name</b>, for the following comments:<br>

<tt>$comments</tt></p>

<p>I Will reply to you at <i>$email</i></p>\n";

 

?>

</body>

</html>

 

*******************************************************************

 

Notice: Undefined index: name in C:\xampp\htdocs\handle_form.php on line 10

 

Notice: Undefined index: email in C:\xampp\htdocs\handle_form.php on line 11

 

Notice: Undefined index: comments in C:\xampp\htdocs\handle_form.php on line 12

Thank you, , for the following comments:

 

I Will reply to you at

Undefined index simply means PHP can't find a index (such as 'name' or 'email') in a array ($_REQUEST).

 

It looks like no data is being passed to the page. Be sure you all your inputs on the form page have the correct name values. It should look something like this:

<form action="handle_form.php" method="post">
    <input type="text" name="name">
    <input type="email" name="email">
    <textarea name="comments"></textarea>
    <input type="submit">
</form>
I would also swap out $_REQUEST with $_POST so the method is explicit, but what you've written is still perfectly valid.

Edited by jacobg830

Are you visiting handle_form.php without pressing the submit button on the form? Also, make sure caching in XAMPP is disabled.

 

<input type="text" name="email"> You mean

 

type="email" is valid HTML5, the browser checks the user has entered a valid email address.

I just go to the handle_form.php through the localhost

 

You need to go to the HTML form page, fill it in and click submit. This should then take you to the handle_form.php. Visiting handle_form.php directly through http://localhost/handle_form.php means no data is being sent to it.

Can I just suggest ...

 

<?php # Script 2.2 - handle_form.php

// Create a shorthand for the form data.

if($_SERVER['REQUEST_METHOD']=='POST') { // Only works if posted.
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];

// Print the submitted information.
echo "<p>Thank you, <b>$name</b>, for the following comments:<br>
<tt>$comments</tt></p>
<p>I Will reply to you at <i>$email</i></p>\n";
}
?>
</body>
</html>

 

You could also do with some validation and common spam traps.

And some sanitisation!

 

Lol yeah that's a given, I bundle anything to do with user input under validation (e.g. data types, sanitation, email validation etc) whereas I bundle anti-spam bits prior to any of this as if I detect its automated then I generally kill the post before processing any of the fields.

I'm sure YOU do, but I bet the OP doesn't. Validation and sanitisation are definitely 2 topics worth knowing well before working with any kind of form submission...sanitisation being the more important one for security.

 

As for captcha I avoid them like the plague, honey potting is my preferred method and works surprisingly well.

 

For sure, but since I write procedural with each post field (after spam traps) gets tested for valid type (e.g. number only, no weird cc: in posts etc) and then escaped before storing which combined is validation and sanitation or am I missing something?

 

Edit: Forgot to say I thought the OP was just about why it wasn't working rather than asking for a full tech demonstration of the correct way to write the whole thing in php ... e.g. $_POST over $_REQUEST.

Edited by BrowserBugs

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.