output_add_rewrite_var()
As documented here
This function adds another name/value pair to the URL rewrite mechanism. The name and value will be added to URLs (as GET parameter) and forms (as hidden input fields).
So the following code is supposed to do the trick
<?php
output_add_rewrite_var('var', 'value');
echo 'link';
echo '<form action="test.php" method="post">
<input type="text" name="var2" />
</form>';
?>
On form it works fine, and add a hidden field. But the URL(a tag) is still the same.
http://localhost/test.php
I'm expecting
http://localhost/test.php?var=value
How to fix this?
It seems that if you're using PHP >= 7.1.0 the default tag in url_rewriter.tags is form.
So what you're gonna have to do is change this line in php.ini file:
;url_rewriter.tags
To:
url_rewriter.tags = "a=href,area=href,frame=src,form=,fieldset="
Note: The semicolon at the beginning of the line must be removed
Related
How can I update a url variable value?
The url will look like that for example:
www.example.com/product.php?.........&page=1...........
I would like to change page value from 1 to 2, the reason that I typed dots instead of real url is since the url is dynamic and not static.
So how can I do that?how can I update and url variable value?
EDIT
I will refresh the page with the new value so the page will be re-filtered.
Can you try this,
$QUERY_STRING = $_SERVER['QUERY_STRING'];
echo $QUERY_STRING = str_replace('page=1', 'page=2', $QUERY_STRING);
PHP does not control your browser. The user and/or Javascript does. This means, you can not update a specific variable in the URL. (This variable is also called a HTTP GET Parameter).
What you have are below options:
Use an HTML form, with action="" & method=GET. Use hidden fields, with name=page and value=<number>.
<form action="" method="GET">
<input type="hidden" name="page" value="2" />
<!-- Use PHP to echo out all other GET parameters into hidden form fields -->
<input type="submit" value="click me to go to page 2"/>
</form>
Use Javascript: Parse out the GET parameters, and modify it.
I am designing one HTML form with index.html page. Default values are on PHP page, like name, for form. Now my query is how can I take these values on to the HTML page?
For example :
default.php
$name="poorna";
...
...
in index.html
<form>
<input type="text" value="<?php echo $name; ?>" >
</form>
How can this be possible ?
quick and dirty:
change index.html to index.php
<?php include 'default.php'; ?>
<form>
<input type="text" value="<?php echo $name; ?>" >
</form>
hope it helps
for a shorter version of echo you can use <?= $name ?>;.
Notice:
the short tags only work if you set the correct setting in the php.ini
$ grep 'short_open' php.ini-production
; short_open_tag
short_open_tag = On //Default Off
If i am not wrong since PHP 5.4 this option is set to On by default
Without .php extension server dont accept php tag. Save the file as php is better...
On the same page I have
$hello = 'Hello!';
$_POST['hello'] = '123';
If I echo $hello, instead of getting 'Hello!' I get '123'.
How should I handle variables and $_POST variables with the same name?
This is an example of the real problem:
I have a signup form that looks like this (here's a minified sample of fields).
Each input field has a label and the string variable in the label has the same name as the input.
<form id="form1" action="post.php">
<span class="label"><?=$fullname?></span>
//$fullname='Please enter your name';
<input name="fullname" id="fullname" type="text">
<span class="label"><?=$email?></span>
//$email='Please enter your email';
<input name="email" id="email" type="text">
<input name="button1" id="button1" type="submit">
</form>
When I submit the form I post it to the same page and I display the values the user had filled out. Only that now, instead of $fullname displaying the value of the variable $fullname, it displays the value of $_POST['fullname']. Why does this happen?
probably you have register_globals turned on which is something that has been advised against for years already :) see here for details: http://php.net/manual/en/security.globals.php
The problem probably lies with register_globals in php's .ini file. Turn this off, restart php and it should be fixed.
Try this to check the setting at the moment of execution of the code:
echo ini_get("register_globals");
You must to set method="POST" attribute in form declaration. And may be you have register_globals option is enabled.
Check your php.ini for the register_globals setting. It is most likely set to on, you should turn it off.
Well if register_superglobals is off then you are doing similar in your script
like
foreach($_REQUEST as $key => $val) // or $_POST or $_GET
$$key = $val;
<?php echo $_POST['ss'];?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input name="ss" type="text" />
<input type="submit" name="submit">
</form>
This code should print whatever is enter in text box name="ss" when click submit.
But its not printing. Working with method="get" but not with post, What's the problem.
If you're just refreshing the page, do:
action=''
instead of:
action="<?php echo $_SERVER['PHP_SELF'];?>"
Also, add this to line 2 to see what's being stored (if anything) in the $_POST array:
var_dump( $_POST );
Hmm... so it's empty on submit? Try adding this to the top of your php file:
if(empty($_SERVER['CONTENT_TYPE']))
{
$_SERVER['CONTENT_TYPE'] = "application/x-www-form-urlencoded";
}
Okay, now check your php.ini (normally requires sudo or root in /etc):
post_max_size = 8M
variables_order = "EGPCS"
Do you have those two rules set? If so, be careful of how much memory you're allocating. Anything over 2048MB could start to give you trouble, depending on your system specs.
NOTE: If you make changes to your php.ini file and PHP is running as an apache module, you'll need to restart apache. Something along the lines of:
sudo /etc/init.d/httpd restart
I broken my post method once that I set post_max_size the same with upload_max_filesize.
I think that post_max_size must less than upload_max_filesize.
Tested with PHP 5.3.3 in RHEL 6.0
It may be due to rewrite rules in the .htaccess file.Add this condition to your .htaccess file
RewriteCond %{REQUEST_METHOD} !POST [NC]
OR add this line
RewriteRule ^welcome_post.php - [PT]
Finally ...Got it.... Firstly I have an Article folder in my htdocs file with welcome.php as the php file in focus and a main HTML file , whose contents we will be discussing about.
Here's what worked for me..
Turns out the problem was not XAMPP or any of its related files..
The problem was this :
<form action="welcome.php" method="post">
With this code whenever I pressed the submit button, the url redirects to here file:///C:/xampp/htdocs/Article/welcome.php, Which is not what it needs to be..It has to be a localhost link ..So I changed the value of action attribute to localhost form and now it looks like this
<form action="https://localhost/Article/welcome.php" method="post">
That did the trick..Now the submit button redirects to https://localhost/Article/welcome.php , this link..Which is exactly what is needed..
Remember the browser may ask you for some permission issues ..Just accept them it will run fine...
Best of luck..
P.S : This one is for Windows..Hope it will work also in Linux and Mac.
My friend ran into this problem today. The answer was pretty simple - basically, you have to capitalize the POST part of method="POST"
The final result should look like
<?php echo $_POST['ss'];?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input name="ss" type="text" />
<input type="submit" name="submit">
</form>
First make sure that your web service (GET/POST etc) is acting as desired using the Chrome Advanced Rest Client. Then you should check your PHP part.
I solved mine with including following into header.
Content-Type: application/x-www-form-urlencoded
Just use this in the header while making a request and my problem was solved.
<form action="" method="post"> method="post" is important for POST Data.
Use PHP REQUEST instead:
<form action="" method="post">
<input type="email" name="mail">
<input type="submit" name="submit" value="Submit">
</form>
PHP:
if(isset($_REQUEST['submit'])){
$val= $_REQUEST['mail'];
echo $val;
}
use this instead;
$variable_name = $_REQUEST["ss"];
echo $variable_name;
change your IDE ,i use phpstorm ,it's fantastic but when i use dreamweaver it works probably, for test you can run your page directly from wampserver localhost , i change default port of apache and i think problem is from there , if you use phpstorm or change port of apache server change your IDE.
This question already has answers here:
PHP POST not working
(10 answers)
Closed 8 years ago.
I have the simplest form possible and all I want to do is echo whatever is written in text box.
HTML:
<form action="" method="post">
<input type="text" name="firstname">
<input type="submit" name="submit" value="Submit">
</form>
PHP:
if(isset($_POST['submit'])){
$test = $_POST['firstname'];
echo $test;
}
The problem is it's not working on my server (it works on another server). Does anyone has an idea what could be wrong? There are other forms on the server and are working fine.
I had something similar this evening which was driving me batty. Submitting a form was giving me the values in $_REQUEST but not in $_POST.
Eventually I noticed that there were actually two requests going through on the network tab in firebug; first a POST with a 301 response, then a GET with a 200 response.
Hunting about the interwebs it sounded like most people thought this was to do with mod_rewrite causing the POST request to redirect and thus change to a GET.
In my case it wasn't mod_rewrite to blame, it was something far simpler... my URL for the POST also contained a GET query string which was starting without a trailing slash on the URL. It was this causing apache to redirect.
Spot the difference...
Bad: http://blah.de.blah/my/path?key=value&otherkey=othervalue
Good: http://blah.de.blah/my/path/?key=value&otherkey=othervalue
The bottom one doesn't cause a redirect and gives me $_POST!
A few thing you could do:
Make sure that the "action" attribute on your form leads to the correct destination.
Try using $_REQUEST[] instead of $_POST, see if there is any change.
[Optional] Try including both a 'name' and an 'id' attribute e.g.
<input type="text" name="firstname" id="firstname">
If you are in a Linux environment, check that you have both Read/Write permissions to the file.
In addition, this link might also help.
EDIT:
You could also substitute
<code>if(isset($_POST['submit'])){</code>
with this:
<code>if($_SERVER['REQUEST_METHOD'] == "POST"){ </code>
This is always the best way of checking whether or not a form has been submitted
Dump the global variable to find out what you have in the page scope:
var_dump($GLOBALS);
This will tell you the "what" and "where" regarding the data on your page.
I also had this problem. The error was in the htaccess. If you have a rewrite rule that affects the action url, you will not able to read the POST variable.
To fix this adding, you have to add this rule to htaccess, at the beginning, to avoid to rewrite the url:
RewriteRule ^my_action.php - [PT]
Instead of using $_POST, use $_REQUEST:
HTML:
<form action="" method="post">
<input type="text" name="firstname">
<input type="submit" name="submit" value="Submit">
</form>
PHP:
if(isset($_REQUEST['submit'])){
$test = $_REQUEST['firstname'];
echo $test;
}
Have you check your php.ini ?
I broken my post method once that I set post_max_size the same with upload_max_filesize.
I think that post_max_size must less than upload_max_filesize.
Tested with PHP 5.3.3 in RHEL 6.0
FYI:
$_POST in php 5.3.5 does not work
PHP POST not working
try doing var_dump($_GLOBALS).
A potential cause could be that there is a script running before yours which unsets the global variables. Such as:
unset($_REQUEST);
or even.
unset($GLOBALS);
This could be done via the auto_prepend_file option in the php.ini configuration.
try this
html code
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="firstname">
<input type="submit" name="submit" value="Submit">
</form>
php code:
if(isset($_POST['Submit'])){
$firstname=isset($_POST['firstname'])?$_post['firstname']:"";
echo $firstname;
}
There is nothing wrong with your code. The problem is not visible form here.
Check if after the submit, the script is called at all.
Have a look at what is submitted: var_dump($_REQUEST)
html file and php file both should reside in htdocs folder in c:\apache2 (if you use apache web server).
Open html file by typing http://"localhost/html_file_name.html"
Now enter Your data in fields.. Your code will run..
Try get instead for test reasons
<form action="#?name=test" method="GET">
<input type="text" name="firstname" />
<input type="submit" name="submit" value="Submit" />
</form>
and
if(isset($_GET)){
echo $_GET['name'] . '<br>';
echo $_GET['firstname'];
}