<?php
if (in_array($key,$following)){
echo ' <form id="follow" action= "action.php" method="GET" data-theme="a">
<input type="hidden" name="id" value="$key"/>
<input type="submit" name="do" value="follow" data-theme="a"/>
</form>';
?>
I am trying to style this echo section. I have it outputting to another PHP file that is framed in HTML div tags. How would I go about this? I have everything else on the page styled correctly except for this output.
Edit** I edited the code, that's a form. But anyway, I have another php file that is referencing this php code and on the 2nd php file it is wrapped in html and the div tag on that page shows the echo from this page but I can't get the css to work on that other file. And I have tried #follow. no luck.
create your own function:
function myecho($text){
echo "<div class='your_css_class'>".$text."</div>";
}
And when you want to echo something just write myecho("my message");
Related
I want to create a webpage that posts onto itself text inserted into an input field, using CSS to stylize said text once it becomes part of the page. However, I don't know how to refer to it with a CSS selector. I've done what every HTML-newb tries when encountering a problem and wrapped both the form code and PHP statement in classified DIVs, however, the computer visibly doesn't know what I'm trying to address. Likewise, wrapping the PHP statement in paragraph tags doesn't apply to it the stylization said tags are associated with.
For Reference, Form & PHP Code:
<form method = "post">
<textarea name="input"></textarea>
<input type="submit">
</form>
<?php echo $_POST['input'];?>
My apologies if the solution to this is obvious; I can't find information addressing it.
you could inline style it or with a class.
<form method = "post">
<textarea name="input"></textarea>
<input type="submit" name="submit">
</form>
<div class="input-value">
<?php
if(isset($_POST['submit])) {
echo $_POST['input'];
}
?>
</div>
use .input-value class in css
Please try this!
<form method = "post">
<textarea name="input"></textarea>
<input type="submit">
</form>
<?php echo "<div style='color:red;font-family:verdana;font-size:300%'>" .
$_POST['input'] . "</div>" ?>
Are you looking for this? Please let me know! Thanks!
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 have written a script in php to replace in newtopic button in phpbb3
in other question, a user says me this:
In your submit.php, you can retrieve the forum ID using $_GET['f']. Now, to pass it on to application.php, you can use a hidden input field:
<form method="post" action="application.php" accept-charset="utf-8" >
$id = htmlspecialchars($_GET['f']);
<input type="hidden" name="forum_id" value="<?php echo $id; ?>"/>
When you click on the submit button, the forum ID value will also get POSTed, and you'll be able to retrieve it in application.php code using the $_POST['forum_id'].
and my code goes as here:
<form method="post" action="application.php" accept-charset="utf-8" >
$id = htmlspecialchars($_GET['f']);
<input type="hidden" name="forum_id" value="<?php echo $id; ?>"/>
.............
<fieldset class="submit-buttons">
<input value="Submit" class="button2" type="submit">
</fieldset>
This code is embedded in submit.php to use phpbb3 template.
and application.php goes as here
So I click on new topic button, and I redirect to submit.php?mode=post&f=3 and in that php there is embedded the html, the problem is that with the solution, I receive the next error:
"The forum you selected does not exist" and the addresswar goes as: viewforum.php?f=&sid=a69fb9f491d2adc11c4be3a6dac02774
so I think that forum_id (in thos case is "3" (&f=3) is not correctly sent throught php scripts
I would appreciate some help
You need to add $id = htmlspecialchars($_GET['f']); inside the <?php ?> tag,
<?php $id = htmlspecialchars($_GET['f']); ?>
Suppose I have a form. After I submit my form, the data is submitted to dataprocess.php file.
The dataprocess.php file processes the variable sent via form and echoes desirable output.
It seems impossible to echo to a specified div in specified page only using PHP (without using AJAX/JavaScript as well). I do not want to use these because some browsers might have these disabled.
My concern is that I want to maintain the same formatting of the page that contained the form element. I want the form element to be there as well. I want the query result to be displayed below the form.
I could echo exact html code with some modification but that's memory expensive and I want it systematic.
Is it possible to process the form within the same page? Instead of asking another .php file to process it? How does one implement it?
The above is just for knowledge. It will be long and messy to include the PHP script within the same HTML file. Also, that method might not be efficient if I have same process.php file being used by several forms.
I am actually looking for efficient methods. How do web developers display query result in same page? Do the echo all the html formatting? also, does disabling JavaScript disable jQuery/AJAX?
Yes it is possible to process the form on the same page.
<?php
if (isset($POST))
{
//write your insert query
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<!-- Your form elements and submit button -->
</form>
<table>
<?php
//your select query in a while loop
?>
</table>
</body>
</html>
But if you choose this technique instead of ajax, you have to refresh all the page for each insert action.
An example
<div id="dialog-form">
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<table>
<tr>
<td>Job</td>
<td>
<input type="text" name="job" />
</td>
</tr
</table>
<input type="submit" value="Insert" />
</fieldset>
<input type="hidden" name="doProcess" value="Yes" />
</form>
</div>
<?php
$myQuery= $db->prepare("INSERT INTO Jobs (job) VALUES (:p1)");
if (isset($_POST['doProcess']) && $_POST['doProcess'] == 'Yes')
{
$myQuery->bindValue(":p1", $_POST['job'], PDO::PARAM_STR);
$myQuery->execute();
}
?>
if you really dont want to use ajax (which i think you should). You can do something like this.
<form action="" method="POST">
<input type="text" value="something" name="something_name"/>
<?php
if(isset($_POST['something_name'])){
echo '<div id="display_something_name_if_exists">';
echo $_POST['something_name'];
echo '</div>';
}
?>
</form>
Basically what it does is submits to itself and then if there is a submission (tested with isset), it will echo a div with the correct information.
<form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validateForm(this);" >
<p>
<input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="myClickHandler(); return false;" />
</p>
</form>
<script type="text/javascript">
function myClickHandler(){
if(validation()){
showConfirm();
}
}
</script>
<?php
session_start();
$outputDetails = "";
$outputDetails .= "<table id='sessionDetails' border='1'>
<tr>
<th>Number of Sessions:</th>
<th>{$_POST['sessionNum']}</th>
</tr>";
$outputDetails .= "</table>";
echo $outputDetails;
?>
Above is the code for my form. What I am trying to do is that if the user submits the form, then it will go back to its own page. But if the "SessionNum" equals '1', then instead of posting the form to itself, it should post the form or in other words navigate to the "session_marks.php' page but it is not idng this, if sessionNum equals 1 then it still submits form or navigate back to its own page, what am I doing wrong?
Also lets say it displays a number for the sessionNum and then I submit the form and it submits the form back to itself, the number disappears, how do I keep the number displayed when submitting the form to itself?
Thanks
Where is the conditional logic to change the target of the form post? All I see in the form tag is this:
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"
This will always set the form's action to be the current PHP file, not any other PHP file. If you want to conditionally post to a different file, you'll need to add conditional logic in there. Something like this (though there may be better ways to do it, keep in mind that I'm very out of practice with PHP):
action="<?php $_POST['sessionNum'] == 1 ? echo 'session_marks.php' : echo htmlentities($_SERVER['PHP_SELF']); ?>"
As for the number disappearing, I don't see any form element with the name sessionNum. If there isn't such a form element, then there will be nothing in $_POST['sessionNum'], so the number will "disappear" because there's no value to be displayed.
If the above is your actual code, session_start(); has to be placed before ANY other output (html, php's echo, print etc...)