How to transfer text box from page to another page - php

I am new to php and I need some help.
I have two sites. And I want to display text box from my edit.php on index.php.
<form method="post">
<textarea name="content" cols="40" rows="5">
Enter your comments here...
</textarea><br>
<input type="submit" value="Submit" />
</form>
<?php
$content = $_POST["content"];?>
How do I transfer variable $content to my index page?

To address your comments. (Don't down rank me... his original question was not precise).
// on your edit page
<form method="post">
<textarea name="content"></textarea>
<input type="submit" />
</form>
// when you submit your edit page
$filename = '/mytextarea.txt';
$content = file_put_contents( $filename, $_POST['content'] );
// on your index page
$filename = '/mytextarea.txt';
$content = file_get_contents($filename);
if( ! empty( $content ) ){
echo '<div>'.$content.'</div>';
}

From edit you want to make sure your action points to index.php
edit.php
<form method="post" action="index.php">
<textarea name="myTextBox" cols="40" rows="5"></textarea>
<input type="submit" value="Submit" />
</form>
In index.php, you can access the variable with $_POST["myTextBox"], this can be outputted as text or as a value in the example below. Be sure to use htmlentities when including the value back with a form field, this will prevent "injection hacking".
index.php
<?php echo $_POST["myTextBox"] ?>
<form method="post" action="index.php">
<textarea name="myTextBox" cols="40" rows="5"><?php echo htmlentities($_POST["myTextBox"]); ?></textarea>
<input type="submit" value="Submit" />
</form>

Well, just set the action on the form to the page you want it to post to - example:
Random Page:
<form method="post" action="/index.php">
<textarea name="content" cols="40" rows="5">
Enter your comments here...
</textarea><br>
<input type="submit" value="Submit" />
</form>
Index.php:
if(isset($_POST['content']) && !empty($_POST['content'])){
echo htmlspecialchars($_POST['content']);
}
At least I think this is what you are asking?
If you are echoing a random textbox to a page, make sure to sanitize it using htmlspecialchars()

Try to action your form to your index.php :
<form method="post" action="/index.php">
</form>
With that, once you submit your form, your page index.php will be loaded, with values of your form in $_POST.

// on your edit page
<form method="post" action="index.php">
<textarea name="content"></textarea>
<input type="submit" />
</form>
// on your index page
if( $_SERVER['REQUEST_METHOD'] == 'POST' ){ // This will prevent the textarea from
// being shown unless some form posted to this page
echo '<form method="post">
<textarea name="content">'.$_POST['content'].'</textarea>
<input type="submit" />
</form>';
// If it's not set or it's empty, then it just won't show anything....
// you don't need to check for that unless you want to set a value when it is empty
}

Just change your form to post to the second site instead of to itself, then echo the $_POST['content'] on your index.php page
www.firstsite.com/edit.php
<form action="www.secondsite.com/index.php" method="post">
<ul>
<li>
<textarea name="content" cols="40" rows="5">Enter your comments here...</textarea>
</li>
<li class="submit">
<input type="submit" value="Submit" />
</li>
</ul>
</form>
www.secondsite.com/index.php
<?php echo $_POST['content']; ?>

Related

Get ID through input and redirect to page with this ID

everybody! I need your help or my head will blow up soon! I feel the solution is easy but...
When user enters ID and Date and clicks Submit button he must be redirected to the devis.php page with the client id entered before. Here is the initial code
<?php
include("db.php");
if( isset( $_REQUEST['submit'] ) )
{
$id=$_POST['client'];
$date=$_POST['calendar'];
?>
<h1>IDENTITE CLIENT:</h1>
<label>Client ID <input type="text" name="client" ></label>
<br>
<br>
<label>Date de 1ere intervention <input type="date" name="calendar"> </label>
<br>
<input type="submit" name="submit" value="submit" >
But in this code the inputs can be visible only after clicking Submit and if to get them out of php tags, the variable Id isn't recognised and no redirection is following.
Thank you for your help and time!
ADD THIS TO YOUR PHP CODE
if( isset( $_REQUEST['submit'] ) )
{
$id=$_POST['client'];
$date=$_POST['calendar'];
header('location:devis.php?id='.$id.'&date='.$date);
}
And set form action attribute to blank action=""
The easiest way to do this is make a form like this:
<form method = "POST" action = "devis.php">
<h1>IDENTITE CLIENT:</h1>
<label>Client ID <input type="text" name="client" ></label>
<br>
<br>
<label>Date de 1ere intervention <input type="date" name="calendar"> </label>
<br>
<input type="submit" name="submit" value="submit" ></a>
</form>
now in devis.php, you should be able to get the ID from previous page like this:
if ( isset($_POST['submit']) )
{
$id = $_POST['client']; // ID inputted from the previous page.
}
Create a normal HTML form along with your required inputs inside form with post method and action with value devis.php since you want to redirected to devis.php
HTML
<html>
<head></head>
<body>
<form method="post" action="devis.php">
<label>Client ID :</label><input type="text" name="client" ><br><br>
<label>Date de 1ere intervention:</label> <input type="date" name="calendar"> <br><br>
<input type="submit" name="submit" value="submit" >
</form>
</body>
</html>
Your devis.php page should do it. Here I am just echo-ing the values just to give you a clue of how to retrieve it. You can use it the way you want.
devis.php
<?php
if(isset($_POST["client"]){
echo 'Client ID: '.$_POST["client"].'<br>';
}
if(isset($_POST["calendar"]){
echo 'Date: '.$_POST["calendar"];
}
?>

submitting result to the end of the url instead of adding an index.php

Id basically like the below submission to place text at the end of the url
example of what i want
http://example.com/(text) -- without the () obviously
example of what i don't want -- http://www.example.com/index.php?firstname=text
<form action="(end of current url)">
<fieldset>
search name
<br>
<input type="text" name="search" value="name">
<br>
<input type="submit" value="Submit"></fieldset>
</form>
id like to fix this via html or php either will do aslong as it submits the request to that :)
thank you in advance.
Using the POST method instead of GET.
<form action="" method="POST">
<fieldset>
search name
<br>
<input type="text" name="search" value="name">
<br>
<input type="submit" value="Submit"></fieldset>
</form>
In short you do the following:
<?php
// Get posted text
$text = strtolower(mysql_real_escape_string($_POST['text']));
// Do some cleanup here
// Redirect to page
if ($text != ''){
header( 'Location: http://www.example.com/' . $text );
}
// HTML output below (not before)
?>
<form method="post" action="">
<fieldset>
Search name<br />
<input type="text" name="text" /><br />
<input type="submit" value="Submit" />
</fieldset>
</form>

Textarea wont set $_POST

<textarea name="pageeditor" id="tbMsg" style="height:350px;width:100%;"></textarea>
is the code to my textarea.
It doesn't submit (wont set $_POST['pageeditor']) but it will if I do:
<textarea name="pageeditor" id="tbMsg" style="height:350px;width:100%;">TEXT HERE</textarea>
which doesn't make any sense to me. It doesn't submit any text I type in on the page, but will if I hard code it into the page.
any ideas?
I tried this and it seems to be displaying the textarea text that I enter.
<?php
echo "<pre>";
print_r($_POST);
echo $_POST['pageeditor'];
echo "</pre>";
?>
<form method="post">
<textarea name="pageeditor" id="tbMsg" style="height:350px;width:100%;"></textarea>
<button type="submit" name="form_submit"> Submit</button>
</form>
<p>
<?php
if(isset($_POST['submit']))
{
echo $_POST['textarea'];
}
?>
</p>
<form method="post">
<textarea name="textarea" cols="30" rows="10"></textarea>
<button type="submit" name="submit">Submit</button>
</form>

Unable to access _POST values PHP

Find below my form and the action page it submits to. The _POST array is empty. Not sure how. Please help.
index.php
<form method="post" action="track-them.php">
<input type="text" width="255" id="txt" />
<textarea id="ta" type="text" cols="25" rows="4"></textarea>
<input type="submit" id="check-button" value="Ok" />
</form>
track-them.php
<?php
include_once('../simple_html_dom.php');
print_r($_POST);
?>
Both fields txt & ta have values but the output I see when I click submit is:
Array ( )
Add name attribute to your form elements:
<form method="post" action="track-them.php">
<input type="txt" width="255" id="myurl" name="myurl" />
<textarea id="ta" name="ta" type="text" cols="25" rows="4"></textarea>
<input type="submit" id="check-button" value="Ok" />
</form>
Give your inputs a name. The browser passes the name attribute not the id.
If you put the print_r($_POST) above the inclution what is the result ?
Please add name attribute for each from element

Passing data from one textarea to another on a different page using POST

I have a problem of passing data from one textarea to another textarea on another page. I’m using php POST function in order to retrieve data from the first page. Also, I have JavaScript inserting data into the textarea on the first page with the help of JSON and PHP talking to MySQL database. Inserting data into textarea from the database on the first page works.
When I click on the submit button on the first page, no data is passed to the second page. Many thanks for your help.
Page 1
-----------------------------------------------------------------------------------------
<form action="page2.php" method="post" id="role" name="roleForm">
<fieldset id="fieldset">
<legend id="legend">Background</legend>
<p>
<label for="background"></label>
<textarea name="background" cols="71" rows="10" id="backgroundtext">
</textarea></p>
</fieldset>
<br></br>
<p><input type="submit" name="Submit" value="Add role to job description" id="addjobdesc" /></p>
</form>
JavaScript file (part of the file)
---------------------------------------------------------------------------------------
function set_background (newValue)
{
var field = document.roleForm.backgroundtext;
field.value = newValue;
}
page2.php
-------------------------------------------------------------------------------------------
<fieldset id="fieldset">
<legend id="legend">Background</legend>
<p>
<label for="background2"></label>
<textarea name="background2" cols="71" rows="10" id="backgroundtext2" value="<?php echo $_POST["background"]; ?>"/>
</textarea></p>
</fieldset>
<br></br>
You have to write the content of the textarea BETWEEN the tags, not into a value attribute:
<textarea name="background2" cols="71" rows="10" id="backgroundtext2">
<?php echo $_POST["background"]; ?></textarea>
Be aware that this code is extremly unsafe! If the $_POST["background"] contains HTML it will be brake down your html-code etc.
Shouldn't it be:
<textarea name="background2" cols="71" rows="10" id="backgroundtext2">
<?php echo $_POST["background"];?>
</textarea>

Categories