Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6711701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:10:19+00:00 2026-05-26T08:10:19+00:00

Just a general question. In terms of form actions if the form is submitting

  • 0

Just a general question. In terms of form actions if the form is submitting to it’s parent page I realize that you can use “” or “#” to submit the form. Now my question is when writing a php page that has both the handler and the form I was told it was best to write a form action like this:

action="<?php echo $_SERVER['PHP_SELF'] ?>"
//or
action="<?php echo $_SERVER['SCRIPT_NAME'] ?>"

Now why would you need to add this inline script if you could have the form submit to itself using ‘#’ or just simply not setting the form action. I’m just curious, as adding in that php does create bulky and messy looking form code (which is already bulky and messy looking).

I also understand that the alternate ‘#’ and “” could be used in cases that you aren’t using PHP, but I guess the real question is why add the PHP if you don’t need it (in instances that the form is submitting to a php page).

thanks,
Brodie

Mahalo guys for all the responses. I realize that using the PHP code to generate the url is probably (in most cases) the route to take, as all it would take is for an update to a browser or to HTML in general to say “” and “#” are invalid operators for submitting to the root page. Also I know that the ‘#’ is for referencing an anchor on the same page, but I figured I’d see what everyone’s take on it was.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:10:20+00:00Added an answer on May 26, 2026 at 8:10 am

    First of all the easy part: why put something into the value of action in the first place.

    Well, the HTML 4 spec says (emphasis mine):

    action = uri

    This attribute specifies a form processing agent.
    User agent behavior for a value other than an HTTP URI is undefined.

    Therefore, while practically all browsers will end up submitting the form to the script itself, technically this is a happy coincidence that you should totally not rely on. However, this is not a problem for HTML 5.

    In addition, # by itself is not a valid URI as per the W3C’s definition, so that should be ruled out as invalid as well.

    Now for the other half: how to get the current URL in PHP.

    For basic usage, you can use either one of $_SERVER['REQUEST_URI'] and $_SERVER['PHP_SELF'] for this, depending on if you want to preserve any GET parameters in your current URL (PHP_SELF will not include them, but REQUEST_URI will).

    In more advanced scenarios (e.g. writing code using a framework) it would be better to use the framework’s own URL-generating utility functions to generate the URL for you (this would take routing etc into account, so is preferable).

    Update: I misread the HTML 5 spec, which says you can leave the action blank.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a general question: Is there a query/command I can pass to SQL Server
It's likely that this is just a general Python Tkinter question, not necessarily a
Friend it just general question . How can write and retrieve the data on
Just a general question that I've been wondering about for a while. I write
Just a general question, I'm developing an ASP.NET MVC 3 web application that reads
Just a general question regarding the difference between extending a class and implementing it.
just a general question, do you ALWAYS have to handle error? i was just
Just a general curiosity question. Why is this namespace System.Collections.Generic added by default in
just had a general question about how to approach a certain problem I'm facing.
i just create reading file feature. In general, what kind PHP class that usually

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.