How to send text area content to next page via post method? - php

I got a textarea that has some html code in it. I want to send the content of this textarea without any change to next page via post method.
<html>
<form id="myform" name="myform" action="./getdata.php" method="post">
<td><textarea rows="7" cols="15" name="outputtext" style="width: 99%;"></textarea></td>
<input type="submit">
</form>
</html>
and my php code :
<?
$file_contents = $_POST['outputtext'];
?>
<textarea rows="30" cols="150"><?PHP print_r($file_contents); ?></textarea>
The problem with my code is that the orginal content of my first textarea gets changed when it sends to next page! For example:
<a href="/season/episodes.php?name=ok&id=1">
becomes:
<a href=\"/season/episodes.php?name=ok&id=1\">
could you guys how i can preserve the original html content without it changes in next page ?(Note all my html content changes in second pages which i dont want to change).My second textarea in second page is for testing purpose and i actually want to parse orginal value of $file_contents but for some reason it changes!

In your second PHP script, simply use strip_slashes to remove the extra slashes in the passed text:
<?
$file_contents = stripslashes($_POST['outputtext']);
?>
<textarea rows="30" cols="150"><?PHP print_r($file_contents); ?></textarea>

Related

HTML + PHP how to prevent webpage from displaying anything until submit is pressed

I am new to both HTML and PHP and I encountered a problem when working on some simple projects. Lets say I have a text bar on my webpage and I want to display the text written in text bar on webpage after the user enters some text and presses the submit button. My problem is that the webpage shows the output when the webpage first loads. Is there a way to prevent the php code from executing untill the submit is pressed ?
Here is a sample code code that indicates the problem I am referring to.
<html>
<body>
<form action="./index.php" method="GET">
First Name: <input type="text" name="first" maxlength="50"><br/>
<input type="submit" value="GO"/>
</form>
</body>
</html>
<?php
$text_var = $_GET[first];
echo "This was typed into text bar" . $text_var;
?>
So "This was typed into text bar" is outputted right away when website loads.
I want it to be outputted only after submit button is pressed.
Thanks.
you need to split it up the form should be showed if nothing is submited so either check the value or the submit button
make sure you keep the html format. look at label tags to describe form inputs
<html>
<body>
<form action="./index.php" method="GET">
<label for="first">First:</label>
<input id="first" type="text" name="first" maxlength="50"><br/>
<input type="submit" value="GO"/>
</form>
<?php
if (!empty($_GET['first'])) {
//take care you escape things never output user input (XSS)
$op = htmlspecialchars($_GET['first']);
echo "This was typed into text bar" . $op;
}
?>
</body>
</html>
Check if $_GET['first'] exists. This is is usually done as the following:
View
<form action="index.php" method="post">
<!-- input fields here -->
<input type="submit" name="submit" value="GO"/>
</form>
Controller
<?php
if (isset($_POST['submit'])) {
// process post
} else {
// display the form
}
<?php
if(isset($_GET['submit'])){
$text_var = $_GET[first];
echo "This was typed into text bar" . $text_var;
}
?>

Code in original form

I have HTML code for a table in database. I want to present that code in its original form in a textarea so that I can make changes in it. When I echo it appears in compiled form (table), not in original HTML code. How can I display its original HTML code?
<textarea rows="40" cols="30" name="content" id="content">
<?php echo '<pre>'.$row['content'].'</pre>'; ?>
</textarea>
You can use the <code> tag to achieve this.
Try replacing < by <
<?php echo '<pre>'.str_replace('<', '<',$row['content']).'</pre>'; ?>

Form Hidden Field Prints out Content to Webpage

I have the following form code:
<form action="pdf.php" method="POST" id="pdfform">
<input type="hidden" name="htmlcontent" value="<?php echo $content ?>" >
<li>Download as PDF</li>
</form>
However, what i realise is that the hidden field prints out the content to the HTML page as well, and there are some extra " and > which should not be there.
What i think could be the issue is because the role of the form is to send the html data to a PHP script to convert it to a PDF, the variable $content contains html code, for example: <p>Test 3</p><p><img alt="Cancer" src="http://breakthroughs.cityofhope.org/wp-content/uploads/2013/02/lung-cancer.jpg" style="height:375px; width:500px" /></p>
This could be one of the causes of the issue and the html prints out the extra "> at the end of the value inside the hidden form as well.
Anyone could find out the reason?
Not sure if this is what you want, but have you considered using jquery to set the hidden field? for example (after ensuring you have no single quotes in your $content variable):
<script type='text/javascript'>
$('[name=htmlcontent]').val('<?php echo str_replace("'","`",$content) ?>');
<script>

php how to get the textarea tag from my sql in a textarea in php

I have a code which is all working right but when the code in the database has a it goes wrong
code like this
<tr><td><b>EN Page Content : </b></td><td><textarea name="pageContent" cols="150" rows="100"><?php echo getContentWithIndex("posts",$_GET['pageID'],"content");?></textarea></td></tr>
and content is like this
<textarea placeholder="Message*:" data-constraints='#Required #Length(min=20,max=999999)' name="SenderHRMessage"></textarea>
so it has the end of the </textarea> as an end for the first one and never display any other content in the first textarea.
Change your code to this: (I have reformatted it so that it fits on the SO post)
<tr>
<td><b>EN Page Content : </b></td>
<td>
<textarea name="pageContent" cols="150" rows="100"><?php
echo htmlentities(getContentWithIndex("posts",$_GET['pageID'],"content"));
?></textarea>
</td>
</tr>
The reason is that if you have HTML code that you want to display as HTML code you need to encode it to text.
See: http://php.net/manual/en/function.htmlentities.php

I'm having some issues using Html value

I've a column inside my table to put Html codes, I will use this table for email templating.
I have inside my page, all the templates inside my table, with two buttons, one to remove, and another one to edit.
The edit button shows the code inside a textbox, and to do the preview I did an echo to the code column.
<div class="tempcolumn">
<div><textarea name="ai" rows="15" cols="100" name="code" placeholder="Code">
<?php echo $get_temp; ?></textarea></div>
</div>
Preview
<div class="tempcolumn">
<p><?php echo $get_temp; ?></p>
<div></div>
</div>
To recognize the code and the id i created an hidden input
<input type="hidden" name="temp_id" value="'.$val['template_id'].'">
<input type="hidden" name="temp_code" value="'.$val['text'].'">
The script is working, but when i insert inside the code column some "<" or "=" doesn't work
Is inferfering because it reads the input value like this:
<input type="hidden" name="temp_id" value=" Value here + 'random character that closes the tag' ">
Is there a easier way to do that?
Thanks
You can try;
htmlspecialchars($value)
This will convert html characters to their non-interfering cousins.
See http://docs.php.net/manual/en/function.htmlspecialchars.php as I can't post the equivalents without them becoming characters.

Categories