The script above works fine for adding names to a list in a html page.

I want to change the form action from "simple.php" to "names.html", so that once someone submits the form they are brought to the html page with the list of names. However, when I change the form action to "names.html", the name submitted in the form, is not added to the list of names in the html file. Why is that?

How can I alter the script so that when the form is submitted the name is added to the list and the user is brought to the names.html page.

Thanks!

vectorialpx
—
2013-01-28T15:29:05Z —
#2

Why don't you just add a header('Location: names.html'); after the fclose($handle);

2ndmouse
—
2013-01-28T15:33:31Z —
#3

What code processes your form data in the file 'names.html'

For php code to work, the file must have the extension '.php'You can't simply change a php file extension to html and expect to work.

Why do you need to do this anyway? Just echo your html in the php file.

Fergal
—
2013-01-28T16:10:11Z —
#4

vectorialpx said:

Why don't you just add a header('Location: names.html'); after the fclose($handle);

Thank you vectorialpx, that works perfectly.

Thanks 2ndmouse, that helps me understand why it wouldn't work.

2ndmouse said:

...Just echo your html in the php file.

I want to create a new html file for the list of names submitted from the form.

Why don't you just add a header('Location: names.html'); after the fclose($handle);

I want to add to this answer that the most proper way in this case is to do a redirection with the 303 "See Other" http status code, which is just intended for the purpose of redirecting from a POST request - this way you will avoid some minor edge-case inconveniences in some browsers. Moreover, Location requires an absolute URL. The code therefore should be something like that:

In a simple structure, it does not require.However, your 303 completion is a better practice.

One other small thing: after the header it's recomended to add an exit;

Lemon_Juice
—
2013-01-29T09:14:21Z —
#8

vectorialpx said:

In a simple structure, it does not require.

What does it mean "in a simple structure"? Can you back up your claim? The HTTP specification clearly states that The field value consists of a single absolute URI.

vectorialpx
—
2013-01-29T11:18:46Z —
#9

Lemon_Juice said:

What does it mean "in a simple structure"? Can you back up your claim? The HTTP specification clearly states that The field value consists of a single absolute URI.

A simple structure is: a no-rewrite interface (just simple.php, no rewrite engine) and a browser (not talking about console).The www.w3.org directive is about general headers but the browser also accepts relative paths, that's what I wanted to say with "not required".The browser knows "where he is" and will redirect relative to the current folder.

However, having an absoluteURL is a better practice but it's not required. In a simple script (like this - a simple form submit) you don't have to use an absolute URL.

As an example of "not required", this works in any browser (or, tell me one that fails):