This question already has answers here:
Make a link use POST instead of GET
(11 answers)
Closed 7 years ago.
Is there a way to replicate this in <a href="blah.php">?
<form action="http://localhost/php/suburb_added.php" method="post">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
in suburb_added.php... i have this to capture
if (!empty($_POST['suburb']))
To a table form....
<td align="left"><a href="suburb_added.php"><?php echo $row['id'];?></td>
how to create the items below from a table? The goal is when I click the result from <?php echo $row['id'];?>, I should be able to get the value of "id" and process it in suburb_added.php using similar to if (!empty($_POST['suburb']))
<form action="http://localhost/php/suburb_added.php" method="post">
<input type="text" name="suburb" size="30" value="" />
what do you whant i don't understand?? I can help you
<?php
if(!isset($_POST['submit'])){
?>
<form action="" method="post" name="submit">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
<?php
} else {
//paste here your code from http://localhost/php/suburb_added.php
echo "you doing post in this page.";
}
?>
<!--Try using header
like this:-->
if($_POST)
{
header('location:login-form.php');
}
else
{
echo "";
}
Change the PHP script so it uses $_REQUEST instead of $_POST. This variable combines the contents of $_POST and $_GET. Then you can have a link like
<?php echo $row['id'] ?>
Related
This question already has answers here:
How do I make a PHP form that submits to self?
(6 answers)
Closed 6 years ago.
I am trying to submit a form by post method on itself. but every time the form submits and page is refreshed. it doesn't show values.
<?php echo $_POST['fname']; ?>
<form method="POST" action='#.php'>
<input type="text" name="fname" id="fname" />
<button id="check" name="check" type="submit">GO</button>
</form>
What's the point, i am missing?
Try this :
<?php echo $_POST['fname']; ?>
<form method="POST" action=""> <!-- not single quote -->
<input type="text" name="fname" id="fname" />
<input type="submit" name="value" >
</form>
Try this...
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "<pre>";
print_r($_POST);
}
?>
<form name="test" action="" method="post"><input type="text" name="firstName" /><input type="submit" name="Submit" /></form>
I would recommend to write more cleaner way. like this:
<?php
if(isset($_POST['fname']) && !empty($_POST['fname']) ){
echo $_POST['fname'];
}
?>
<form method="POST" action=""> <!-- not single quote -->
<input type="text" name="fname" id="fname" />
<input type="submit" name="value" >
</form>
I am having issues with a piece of code in Joomla. It may be something to do with the plugin that enables the PHP but in case it isn't.
Page 1 has a form
<form action="/index.php/bridge" method="POST" name="postcode">
<div><input style="height: 50px;" type="text" placeholder="Enter Your Postcode..." /> <input type="submit" value="Get Started today!" /></div></form>
The text you input becomes the variable I want to pass over
On Page 2
<?php echo "test";
$postcode=1;
$poster=$_POST['postcode'];
echo $poster;
// You can place PHP like this
?>
Unfortunately, the postcode isn't echoed
Assuming nothing else is the cause of this error, try naming the input you are sending over to postcode:
<form action="/index.php/bridge" method="POST">
<div>
<input style="height: 50px;" name="postcode" type="text" "placeholder="Enter Your Postcode..." />
<input type="submit" value="Get Started today!" />
</div>
</form>
In your PHP code you are echoing $_POST['postcode'] but you are not sending the same variable at the time of form submission from input attribute.
<form action="/index.php/bridge" method="POST" name="demoForm">
<div>
<input style="height: 50px;" name="postcode" type="text" "placeholder="Enter Your Postcode..." />
<input type="submit" value="Get Started today!" />
</div>
</form>
Try this
<form action="/index.php/bridge" method="POST">
<div>
<input name="postcode" style="height: 50px;" type="text" placeholder="Enter Your Postcode..." />
<input type="submit" name="submit" value="Get Started today!" />
</div>
<?php
if (isset($_POST['submit'])){
echo $poster = $_POST['postcode'];
}else{
echo $poster = 1;
}
?>
can we use $_POST 2 times with different page ?
this example ..
action.php
<form action="next.php" method="post">
<input name="test" value="test" />
<button type="submit" name="test">submit</button>
</form>
next.php
<?php
$test=$_POST['test'];
?>
<form action="next1.php" method="post">
<input name="test1" value="<?php echo $test; ?>" />
<button type="submit" name="test1">submit</button>
</form>
next1.php
<?php
echo $test2=$_POST['test1']; >> in here i didnt get test1 value . why ?
?>
Within next.php and action.php you need to change your input type like as
<input type="text" name="test" value="test" />
<input type="text" name="test1" value="<?php echo $test; ?>" />
Within next.php and action.php you were missing the type attr of input tag
and you have same name attributes for submit and input within next.php need to remove or change the value from respective
<input type="submit" value="submit"/>
Below code i have tried my local server and it executed successfully.
action.php:-
<form action="next.php" method="POST">
<input type="text" name="test"/>
<input type="submit" value="submit"/>
</form>
next.php:-
<?php
$test = $_POST['test'];
echo $test;
?>
<form action="next1.php" method="POST">
<input name="test1" value="<?php echo $test; ?>" />
<input type="submit" value="submit"/>
</form>
next1.php:-
<?php
$test2=$_POST['test1'];
echo "------".$test2;
?>
Hope this will help.I think this is achieved your requirement.
If you want to do it within one file e.g. index.php then here is the code
<?php
if(isset($_POST['test'])){
if(isset($_POST['test_text'])){
echo 'Output from NEXT: '.$_POST['test_text'];
}
}
elseif(isset($_POST['test1'])){
if(isset($_POST['test_text1'])){
echo 'Output from NEXT1: '.$_POST['test_text1'];
}
}
?>
<table style="width:100%;">
<tr >
<td style="width:50%;">
<form action="" method="post" name="next">
<input type="text" name="test_text" value="<?php echo isset($_POST['test_text']) ? $_POST['test_text']:''; ?>" />
<button type="submit" name="test">submit test1</button>
</form>
</td>
<td style="width:50%;">
<form action="" method="post" name="next1">
<input type="text1" name="test_text1" value="<?php echo isset($_POST['test_text1']) ? $_POST['test_text1']:''; ?>" />
<button type="submit" name="test1">submit test1</button>
</form>
</td>
</tr>
</table>
I hope this will help.
You need to send the POST value with the second form again, e.g. in a hidden field, otherwise the value won't be sent.
Furthermore your submit button shouldn't have the same name as the input field you want the content from. So change the name of your submit button, e.g.:
action.php
<form action="next.php" method="post"> <input name="test" value="test" /> <button type="submit" name="submit">submit</button> </form>
next.php
<form action="next1.php" method="post">
<input name="test1" value="<?php echo $test; ?>" />
<button type="submit" name="submit">submit</button>
</form>
I'm a beginner in PHP, I'm trying to add Google PR tool in my blog. but i don't know how to make a user input based PHP url.
<?
require("PRclass.php");
$url='http://www.digitcrop.com/';
$pr = new PR();
echo "$url has Google PageRank: ".$pr->get_google_pagerank($url) ;
?>
Exactly what I want.
$url='http://www.digitcrop.com/';
Change to user input url with like below html
<p>
<input name="url[]" type="text" id="url[]" value="http://" size="80" /><br />
</p>
<p>
<input name="findpr" type="submit" value="Find Google PageRank" />
</p>
Depending on your Form method you get it via $_GET['yourinput'] or $_POST['yourinput']
You Need to Submit the form( weather GET or POST Method ) and then Putting the Input Values on correct Locations.
<?php
require("PRclass.php");
if(isset($_POST['sample']))
{
$url=urlencode($_POST['url']);
$pr = new PR();
echo "$url has Google PageRank: ".$pr->get_google_pagerank($url) ;
}
?>
<form name="sampleform" method="post" action="">
<p>
<input name="url" type="text" id="url" value="" size="80" /><br />
</p>
<p>
<input name="findpr" type="submit" value="Find Google PageRank" />
</p>
<input type="submit" name="sample" value="submit" />
</form>
To elaborate on #mfsymb's answer, you should put your input elements inside of a form element. Set the following attributes within the form element tag:
<form action='yourfile.php' method='post'>
Then, you can set your $url variable like so:
$url=$_POST["url[]"];
Read more about it here: http://www.w3schools.com/php/php_forms.asp
Try this
<?php
require("PRclass.php");
if($_POST['sample']!="")
{
$url=urlencode($_POST['url']);
$pr = new PR();
echo "$url has Google PageRank: ".$pr->get_google_pagerank($url) ;
}
?>
<form name="sampleform" method="post" action="">
<p>
<input name="url" type="text" id="url" value="" size="80" /><br />
</p>
<p>
<input name="findpr" type="submit" value="Find Google PageRank" />
</p>
<input type="submit" name="sample" value="submit" />
</form>
First of all, you don't need to use a named array for your input box (name="url[]") since a textbox will be holding a single value only.
The second thing to make note of is that you will need a <form> tag in order to let PHP know that you're submitting some information to work with.
HTML
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>
<input name="url" type="text" id="url" value="http://" size="80" /><br />
</p>
<p>
<input name="findpr" type="submit" value="Find Google PageRank" />
</p>
</form>
<?php echo $_SERVER['PHP_SELF']; ?> tells the form to post the data to the same page.
PHP
// run the below code only if the form was submitted
if(isset($_POST['findpr'])) {
$url = $_POST['url']; // this is where we capture the user input
// making sure the user enters a valid URL
if(!filter_var($url, FILTER_VALIDATE_URL))
{
echo 'The entered URL is not valid. Please try again';
}
else
{
require("PRclass.php");
$pr = new PR();
echo "$url has Google PageRank: ".$pr->get_google_pagerank($url) ;
}
}
This question already has answers here:
How to read the query string in PHP and HTML?
(3 answers)
Closed 9 years ago.
My URL is /mithun/add.php?bc=3
The "bc" being the attribute name. How can I pass this value so that it shows me the value 3 as input on the screen.
My source code:
<body>
<h1>Add new product</h1>
<form action="add.php" method="post">
Barcode: <input type="text" name="bc" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
Thanks in advance.
Replace text type with this Barcode: <input type="text" name="bc" value ="<?php echo $_GET['bc']?>" />
You can access it also from url portion like
<?php $arr = explode("=",$_SERVER['REQUEST_URI']);
echo $arr[1];
?>
<input type="text" name="bc" value ="<?php echo $arr[1];?>" />
you can first get the value by $_GET['bc'] and then echo in the input type and its always good to see weather the $_GET['bc'] is set or not and escape it you can do this by
<input type="text" name="bc" value ="<?php
if( isset($_GET['bc']) && ctype_digit($_GET['bc']))
echo $_GET['bc'];
else
echo "other default" ; ?> />
and if you want to pass value from url use GET method instead
<body>
<h1>Add new product</h1>
<form action="add.php" method="post">
Barcode: <input type="text" name="bc" value="<?php echo $_GET['bc']; ?>" />
<input type="submit" name="submit" value="submit" />
</form>
</body>