如何将表格发布给自己?

I have a page which is accessible via a url - something like this http://websitename/index.php?q=pagename. On this page, I have a form that I would like to submit to the same page so that I could do some post processing. I have tried the following things but couldn't get it to work -

<form name="formname" action="pagename.php" method="post">
<form name="formname" action="" method="post">
<form name="formname" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">

In other words, I would like to submit the form to pagename.php file (where the form resides). The page (pagename.php) is not directly accessible. How do I get this done? I will greatly appreciate any help on this one. Thanks.

Try this:

In HTML5 you can just do <form> and its set to self.

<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post">

OR

<form name="formname" id="mainForm" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['REQUEST_URI'];?>">

OR

<form method="POST" action="<?=($_SERVER['PHP_SELF'])?>">

The point is your $_SERVER variable contains all the information you would require to generate that specific page's URL. If you have decided not to go with the HTML5 way, then one of these options should work. Otherwise you're missing something else not mentioned in your question.

i think this will solve your problem

<form name="formname" action="#" method="post">

Try

 <form method="post">/*your stuff here*/</form> 

and you should add a submit button with attribute "name=submit" so the form could be submitted also track if its have been posted with php then do your actions like below

 if(isset($_POST["submit"])){ /* your code */}