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.
Related
I have insert iframe value into my database using php. I need to display the inserted value in a textbox in another page. But while displaying the data it only displays the value till the first " in the iframe.
my code
<label>Location</label> <input type="text" style="resize:vertical" class="md-input" name="locationmap" class="md-input" value="<?php echo $comp_row['comp_locationmap']?>">
<i class="glyphicon glyphicon-pushpin form-control-feedback glyphiconalign"></i> </div>
The output textbox only displays "<iframe src= "
you need to escape the special characters!
you can do this by using htmlspecialchars() to convert only special characters to HTML entities
echo htmlspecialchars($comp_row['comp_locationmap']);
or htmlentities() to convert all characters to HTML entities
echo htmlentities($comp_row['comp_locationmap']);
This is my second code but the problem is I have 3 queries. So it only returns the last product_id when i Click update it always return product_id=3, but i want update the product_id=2
<form action="update_qty.php" method="POST">
<?php while($getorder = mysqli_fetch_array($order)){ ?>
<input type="hidden" value="<?=$getorder['price']?>" name="actual_price">
<input type="hidden" value="<?=$getorder['product_id']?>" name="product">
<input type="text" value="<?=$getorder['qty']?>" name="qty" size="1" style="text-align:center">
<input type="submit" value="update" name="update">
<?php } ?>
</form>
Your problem is that the PHP is server side and you need something client side to read the value of the text box. You would need a page refresh to pass the text field value to the server so it could write it to the url in the anchor tag. Which is what the form submit would do, but as it would have submitted the value already the anchor tag would be pointless
To do it without a page refresh use Javascript. It would be easy to do with jQuery. You could add an event that writes whatever is entered in the text box the the anchor tags href as it is typed.
I'll do something more like this.
One form per product.In your case when you submit the form the qty value will always be the las found.
<?php while($getorder = mysqli_fetch_array($order)){ ?>
<form action="update_qty.php" method="POST">
<input type="hidden" value="<?=$getorder['price']?>" name="actual_price">
<input type="hidden" value="<?=$getorder['product_id']?>" name="product">
<input type="text" value="<?=$getorder['qty']?>" name="qty" size="1" style="text-align:center">
<input type="submit" value="update" name="update">
</form>
<?php } ?>
You can add more information like this
update
You can not get all values as like that because input name overwrite in every loop iteration.
For multiple values you can try in two ways like:
<?php
while($getorder = mysqli_fetch_array($order)){
$newArr[] = $getorder['price']."~".$getorder['product_id']."~". $ getorder['qty'];
} //while end
?>
<input type="hidden" name="allinputs" value="<?=$newArr?>">
Input field outside the loop.
In php explode array value with ~ and get the all values.
Other solution is that
Your input field name must be change like:
<?php while($getorder = mysqli_fetch_array($order)){ ?>
<input type="hidden" value="<?=$getorder['price']?>" name="actual_price_<?=$getorder['product_id']?>">
<?php } ?>
Change field name in every iteration.
In current scenario either you need three different buttons or the best solution to use AJAX request .
update
On update_qty.php u can use like this
<?php echo $_GET['product_id'];?>
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>
I know this is a weird question and maybe there are better solutions but in this step of my project it difficult to reform project.
I have some pairs of tags in my html similar to this:
<div>
<label for="first">text</label>
<input id="first" />
</div>
<div>
<label for="second">text</label>
<someTag></someTag>
<input id="second" />
</div>
I intend to generate this html with php, some thing like this code:
<?php
$form = new htmlform('formname');
echo $form->label('text');
echo $form->input('first');
echo $form->label('text');
echo $form->input('first');
?>
here is the problem...
as you see I type input id in second line but labels need that id too.
how can I put text in second line and use that in first line?
any byref or some thing.?.
Can you consider some
labeled_input(id, text)
that generates both, the label and the input?
Im trying to make a html form processed in php that outputs to pdf and is print ready.
This is what I have:
A page requesting the categories to include
A page which presents text areas for that categories
A page which displays the final result with an option to print and or make a pdf.
I can make all the information pass along the pages what im lacking is way to display the content properly formatted.
I need this layout:
Text here bold: Description of item
Description of item
(precisely one empty line)
Some more bold text: Description of item
Description of item
and so on.
Im a bit stumbled since the Item descriptions are coming from text areas of which I am able to preserve the line breaks by echoing <.pre> (please excuse the dot, i dont understand how to escape the tag ;) tags along, which end up including all the white space due to the textarea cols.
Assuming I have two textareas and two variables with the titles posting to the last page, how would i go about formatting it properly?
Thank you.
-----EDIT-------
To clarify what I intend:
I have 3 pages:
1 one:
<div class="menu">
Por favor seleccione os conteúdos:
<form name="Categorias" action="Elementos_Descritivos.php" method="post">
<div class="cb-row">
<label for="nome">Nome:</label>
<input id="nome" name="Nome" type="checkbox" value="Nome" checked />
</div>
<div class="cb-row">
<label for="data">Data:</label>
<input id="data" name="Data" type="checkbox" value="Data" checked />
</div>
<div class="cb-row">
<label for="cliente">Cliente:</label>
<input id="cliente" name="Cliente" type="checkbox" value="Cliente" checked />
</div>
<div class="cb-row">
<label for="ob">Observações:</label>
<input id="ob" name="Observacoes" type="checkbox" value="Observacoes" checked />
</div>
<div class="submit">
<input type="submit" value="Seguinte" />
</div>
</form>
</div>
</div>
In this one you choose wich categories go into the doc.
Page 2:
<body>
<?php
$Nome = $_POST["Nome"];
$Data = $_POST["Data"];
$Cliente = $_POST["Cliente"];
$Observacoes = $_POST["Observacoes"];
$Nome1 = "Nome";
$Data1 = "Data";
$Cliente1 = "Cliente";
$Observacoes1 = "Observacoes";
echo "<div class=\"menu2\">
<form name=\"Detalhes\" action=\"Pre_Impressao.php\" method=\"post\">
Por favor preencha os todos os campos em branco:<br/><br/>";
#######################################_NOME_######################################
if ( $Nome == $Nome1 ) {
echo "<div> Nome: <textarea name=\"Nome\" rows=\"6\" cols=\"60\"></textarea></div> <br/>";
}
########################################_DATA_#####################################
if ( $Data == $Data1 ) {
echo "<div> Data: <textarea name=\"Data\" rows=\"6\" cols=\"60\"></textarea></div><br/>";
}
########################################_CLIENTE_##################################
if ( $Cliente == $Cliente1 ) {
echo "<div> Cliente: <textarea name=\"Cliente\" rows=\"6\" cols=\"60\"></textarea></div> <br/>";
}
#######################################_OBSERVACOES_###############################
if ( $Observacoes == $Observacoes1 ) {
echo "<div> Observacoes: <textarea name=\"Observacoes\" rows=\"6\" cols=\"60\"></textarea></div><br/>";
}
####################################################################################
echo "<div class=\"submit\">
<input type=\"submit\" value=\"Seguinte\" />
</div>
</form>
</div>
?>
The second page displays text areas for filling information about hte categories selected in the previous page.
And then page 3, which ought to display the inputs nicely formatted, that's were im stumbled, I know my php is hideous, and i would be better off with a for each loop but for now im trying to focus on getting it done rather than getting it done in a better way :)
If im still not being clear in any aspect please let me clarify so i can improve the post.
Thanks.
You can put PHP code inside normal HTML code (or PDF code), but it might be easier to iterate and generate this way:
If I remember correctly, you can put your data in a table and the formatting will render properly in a PDF. I have also come across the issue that some CSS properties do not render properly in PDF. Hope that helps.