Transfer HTML form value to embedded Php code in same HTML document

I have a HTML form and php code is embedded in same html document and i want to transfer the value from HTML text fields to php which embed in same html document.

I know that action attribute of form tag is used to transfer values and we type “Page Name.php” in action attribute when we transfer value to a separate php page.

But

Situation is different now, i DO NOT want to transfer values to a separate PHP page !

I want to transfer the values to PHP code which is embedded in same HTML document !

Hi saad_ahsan2009

The best way to do this (in most circumstances) is to not include an action attribute with the form at all.

Example:[php]


[/php]

Many will recommend you use a blank action; however, this is wrong, as html requires that an action attribute not be empty. It will almost always work with action="", but it is wrong, nevertheless.

Let me know if this doesn’t work as expected.

Just wanted to clarify the action attribute. I realized that I had left out a few things.

In HTML5 the attribute is not allowed to be blank and is not required.
In HTML4 the attribute is required.

It should work in most cases with or without, but you should use the above guidelines.

Sponsor our Newsletter | Privacy Policy | Terms of Service