Jump to content

[SOLVED] <form name="form">?


Northern Flame

Recommended Posts

I've seen some forms that have something like

<form name="form" method="POST">

whats the point of the name?

I've tried messing around with this i created a php

page like this:

 

<?php
if(!isset($_POST['submit'])){
?>
<form method="POST" name="form">
<input type="text" name="text" size="20">
<input type="submit" name="submit" value="submit">
</form>
<?php
} else{
echo $_POST['form'] . "<br>\n";
echo $_POST['text'] . "<br>\n";
echo $_POST['submit'] . "<br>\n";
}
?>

 

just to see what $_POST['form'] returns is it comes back blank.

is there a point to the name in a form?

Link to comment
Share on other sites

Yes, the form name is used to identify the form.

 

This way, you can use Javascript (heaven forbid!) to update form fields in the correct field. This way, you can have a permanent login script on every page of your site and still have an email form too. I use this principle when designing some of my sites (and yes, I do update forms using JavaScript too sometimes). I think dreamwever names them automatically form1 etc. but it's useful to name them yourself too.

Link to comment
Share on other sites

Like others said, you can use JavaScript to easily access the form like this:

 

<script>
document.write(document.forms['form'].text.value);
</script>

That should print out whatever value in the <input name='text' /> field of the form name 'form'. In your case, it won't print out anything because the input doesn't have a value. But if you change it to: <input name='text' value='hi' />, the code will print "hi"

 

The $_POST['form'] echos back a blank because it has no value. You didn't type anything in (not that you could)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.