this code won't echo out,why??
if (isset( $_post['text']) &&isset( $_post['search for']) && isset($_post['Replace'])){
echo $text= $_post['text'];
echo $replace= $_post['replace'];
echo $search= $_post['searchfor'];
echo $text;
}
?>
<form action='index.php' method ='get'>
<textarea name='text' rows=6 cols=30 > </textarea><br><br>
Search for:<br>
<input type ='text' name='search for'><br><br>
Replace with:<br>
<input type='text' name='replace'><br><br>
<input type='submit' value='Find & Replace'>``
</form>
You're trying to combine$_POST with a form element whose method is set as GET.
Either change your form element's method attribute to POST, or change $_POST to $_GET.
Solution 1
<form action='index.php' method='post'>
if (isset( $_POST['text']) && isset( $_POST['search for']) && isset($_POST['replace']))
Solution 2
<form action='index.php' method='get'>
if (isset( $_GET['text']) && isset( $_GET['search for']) && isset($_GET['replace']))
There is a space in $_post['search for'] but you ask later on the code for $_post['searchfor']
Please use $_POST instead of $_post
field name should not have spaces in it. so use search_for instead
of search for
if (isset( $_POST['text']) && isset( $_POST['search_for']) && isset($_POST['replace'])){
echo $text= $_POST['text'];
echo $replace= $_POST['replace'];
echo $search= $_POST['search_for'];
}
<form action='index.php' method ='POST'>
<textarea name='text' rows=6 cols=30 > </textarea><br><br>
Search for:<br>
<input type ='text' name='search_for'><br><br>
Replace with:<br>
<input type='text' name='replace'><br><br>
<input type='submit' value='Find & Replace'>``
</form>
Your name in the input box and in php is different this is solution for you
if (isset( $_POST['text']) && isset( $_POST['search for']) && isset($_POST['replace'])){
echo $text= $_POST['text'];
echo $replace= $_POST['replace'];
echo $search= $_POST['search for'];
}
<form action='index.php' method ='POST'>
<textarea name='text' rows=6 cols=30 > </textarea><br><br>
Search for:<br>
<input type ='text' name='search for'><br><br>
Replace with:<br>
<input type='text' name='replace'><br><br>
<input type='submit' value='Find & Replace'>
you can also do this by Get method
You should use $_POST instead of $_post . And in form you are specifying method as get, please replace it with post.
The final code is..
if (isset( $_POST['text']) &&isset( $_POST['search for']) && isset($_POST['Replace'])){
echo $text= $_post['text'];
echo $replace= $_post['replace'];
echo $search= $_post['search for'];
echo $text;
}
?>
<form action='index.php' method ='POST'>
<textarea name='text' rows=6 cols=30 > </textarea><br><br>
Search for:<br>
<input type ='text' name='search for'><br><br>
Replace with:<br>
<input type='text' name='replace'><br><br>
<input type='submit' value='Find & Replace'>``
</form>
Related
Actually I need to echoed the form and get the form data in the same php page or send to another php page,A pseudo code is prepared as i cannot post my original code here .
<?php echo "<html><body>";
if(isset($_POST['submit']))
{
$name = $_POST['firstname'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
}
echo"<form action=$_SERVER['PHP_SELF']>
First name:<br>
<input type='text' name='firstname' value='John'><br>
Last name:<br>
<input type='text' name='lastname' value='Rambo'><br><br>
<input type='submit' value='Submit'>
</form></body></html>";
?>
The php page is call/loaded successfully loaded .The form is also working.But
form action=$_SERVER['PHP_SELF'] is not working as well as the code below is also not working.
if(isset($_POST['submit']))
{
$name = $_POST['firstname'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
}
This is tested code. Similar to what your want.
Change $_SERVER['PHP_SELF'] to #
<?php
error_reporting(E_ERROR );
$first = '';
$last = '';
if (intval($_POST['sub'])){
$first = $_POST['firstname'];
$last = $_POST['lastname'];
}
echo <<<EOT
<html><head></head><body>
<form action="#" method="post">
First name:<br>
<input type='text' name='firstname' value="$first"><br>
Last name:<br>
<input type='text' name='lastname' value="$last"><br><br>
<input type='submit' value='Submit'/>
<input type="hidden" name="sub" value=1/>
</form></body></html>
EOT;
?>
In my first page I have this code:
$number="1234567891";
$str="456";
echo "<form action='edit.php' method='POST'><input type='hidden' name='msg' value='$message' />
<input type='hidden' name='text' value='$number' />
<input type='hidden' name='edit' value='$str' />
<input type='submit' name='chedit' value='Go' style='position:relative; top:25px; left: 50%;'>
</form>";
In my edit.php I have this code:
<form action="#" method="POST">
Edit Number
<input type="text" name="change" value="$mumu"/>
<input type="submit" name="pch" value="Change"/>
</form>
<?php
if (isset($_POST["chedit"]))
{
$suj = $_POST["msg"];
$text = $_POST["text"];
$mumu =$_POST["edit"];
if(isset($_POST["pch"]))
{
$change = $_POST["change"];
$obinna = str_replace("$change","$mumu","$text");
echo $obinna;
}
}
?>
My problem is that whenever I put a new text in new form and click submit to edit a character in the old string submitted line the page refreshes and no result is output. Please can anybody sort this out?
// try this ..
if (isset($_POST["chedit"]))
{
$suj = $_POST["msg"];
$text = $_POST["text"];
$mumu =$_POST["edit"];
if(isset($_POST["pch"]))
{
$change = $_POST["change"];
//456 , //555(post value) , //(your text)12345678910
// $obinna = str_replace("Set old value you change in text","set new value you want to set in text ","your orignal text ");
$obinna = str_replace("$mumu","$change","$text");
echo $obinna;
}
}
echo '<form action="#" method="POST">
Edit Number
<input type="text" name="change" value="" placeholder="Change"/>
<input type="text" name="edit" value="" placeholder="Edit"/>
<input type="submit" name="pch" value="Submit"/>
</form>'
Check Demo Url :- https://eval.in/931366
How to dynamically add and remove input fields the form will stay while page refresh using PHP?. could it possible to use session? please any PHP script for this? thanks in advance!!
You could use something like this
<?php
$showEnterOther = "";
$showEnterOtherAsWell = "";
if(isset($_POST["show_form"])) {
$showEnterOther = "<input type='text' name='whatever' />";
$showEnterOtherAsWell = "<input type='text' name='whatever' />";
}
?>
<form action="#" method="post">
<input type="text" name="username" placeholder="Enter Username" value="<?php if(isset($_POST['username'])){echo $_POST['username'];} ?>"/>
<?php echo $showEnterOther; ?>
<?php echo $showEnterOtherAsWell; ?>
<input type="submit" name="show_form" value="Continue!" />
</form>
It keeps (echo)ing sth.
<?php
$offset=0;
if (isset( $_POST['text']) && isset( $_POST['search_for']) && isset($_POST['replace'])){
$text= $_POST['text'];
$replace= $_POST['replace'];
$search= $_POST['search_for'];
$string_length=strlen($search);
if (!empty ($text) && !empty($search) && !empty($replace)){
while ($strpos=strpos($text,$search,$offset))
echo $strpos.'<br>';
echo $offset=$strpos+$string_length.'<br>';
} else {
echo 'please fill all fields';
}
}
?>
<form action='index.php' method ='POST'>
<textarea name='text' rows=6 cols=30 > </textarea><br><br>
Search for:<br>
<input type ='text' name='search_for'><br><br>
Replace with:<br>
<input type='text' name='replace'><br><br>
<input type='submit' value='Find & Replace'>
</form>
You forgot brackets around the while body:
if (!empty ($text) && !empty($search) && !empty($replace)) { // here
while ($strpos=strpos($text,$search,$offset)) {
echo $strpos.'<br>';
echo $offset=$strpos+$string_length.'<br>';
} // here
} else {
Without these brackets just first command is executed (echo $strpos) during the loop and after the loop the second echo is written.
Your code was the same as:
if (!empty ($text) && !empty($search) && !empty($replace)) { // here
while ($strpos=strpos($text,$search,$offset)) {
echo $strpos.'<br>';
} // here the while loop ends
echo $offset=$strpos+$string_length.'<br>';
} else {
You did a mistake { :
while ($strpos=strpos($text,$search,$offset)) {
So :
<?php
$offset=0;
if (isset( $_POST['text']) && isset( $_POST['search_for']) && isset($_POST['replace'])){
$text= $_POST['text'];
$replace= $_POST['replace'];
$search= $_POST['search_for'];
$string_length=strlen($search);
if (!empty ($text) && !empty($search) && !empty($replace)){
while ($strpos=strpos($text,$search,$offset)) { // You forgetten the {
echo $strpos.'<br>';
echo $offset=$strpos+$string_length.'<br>';
} else {
echo 'please fill all fields';
}
}
?>
<form action='index.php' method ='POST'>
<textarea name='text' rows=6 cols=30 > </textarea><br><br>
Search for:<br>
<input type ='text' name='search_for'><br><br>
Replace with:<br>
<input type='text' name='replace'><br><br>
<input type='submit' value='Find & Replace'>
</form>
<?php
if ($_POST['discount'] == 'text1')
echo "Discount Applied!";
else
header('Location:fifapack.html');
?>
I want to be able to add more words after text 1 and not just one valid word.
<div id="dicount">
<form action=discounts.php method=post>
<center>Discount Code:<input type=text name=discount>
<input type=submit value=Apply>
</center>
</div>
This is my html.
You can send several discounts this way:
<div id="dicount">
<form action=discounts.php method=post>
<center>Discount Code:<input type="text" name="discount[]">
<center>Discount Code:<input type="text" name="discount[]">
<center>Discount Code:<input type="text" name="discount[]">
<center>Discount Code:<input type="text" name="discount[]">
<input type=submit value=Apply>
</center>
</div>
And in your php:
$b = filter_input(INPUT_POST, 'discount', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY);
if($b) {
// Do whatever you like with the array of discounts
}
To determine if text1 is in your POST, you can simply use:
if (strpos($_POST['discount'], 'text1')) {
...
}
If I understand you correctly you want to validate $_POST['discount'] against more
words?
<?php
if (($_POST['discount'] == 'text1') or ($_POST['discount'] == 'whatever')) {
echo "Discount Applied!";
}
else {
header('Location:fifapack.html');
}
?>