Forum Moderators: coopster

Message Too Old, No Replies

A simple form query

         

MsCrow

10:32 pm on Aug 17, 2006 (gmt 0)

10+ Year Member



Hello

Can any help me? What I want to do is simple but I can't find anything to help aside from a little php that doesn't help.

I have a form with three text areas, I would like this form, when submit is clicked, to take the user to an HTML formattable output page of the heading of the text areas and the info the user typed in, a preview page if you will. It will be so the user can print the formatted output and file it in their student logs. Or they can save the html output file.

I found a php script that does output to a php file, with the headings and results, only I don't know how to format the php to accept my external css file.

Any help appreciated, I have a headache from searching for options!

Ellie

Here is an example of what I was doing...Any solution is welcome but for a linus server

<?php
$prefer = $_POST["prefer"];
$develop = $_POST["develop"];
$challenge = $_POST["challenge"];
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Personal INFO</title>
<link rel="StyleSheet" href="style.css" type="text/css" />

</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
<p>Which opportunity do you prefer and why?
<textarea rows="5" cols="20" name="prefer" wrap="physical"></textarea>
<br />
How could you use this opportunity to develop yourself?
<textarea rows="5" cols="20" name="develop" wrap="physical"></textarea>
<br />
What might challenge you?
<textarea rows="5" cols="20" name="challenge" wrap="physical"></textarea>
<br />
</p>
<input type="submit" value="submit" name="submit">
</form>

<?
include "<link rel='StyleSheet' href='style.css' type='text/css' />";
} else {
echo "<p>Which opportunity do you prefer and why?</p> ".$prefer." <br />";
echo "Which opportunity do you prefer and why?<br /> ".$develop." <br />";
echo "Which opportunity do you prefer and why?<br /> ".$challenge." <br /></p>";
}
?>

[edited by: MsCrow at 10:43 pm (utc) on Aug. 17, 2006]

barns101

12:01 am on Aug 18, 2006 (gmt 0)

10+ Year Member



I would change the code to this (just rearranged slightly) so that your document remains the same each time, with the stylesheet link, just the content changes:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Personal INFO</title>
<link rel="StyleSheet" href="style.css" type="text/css" />
</head>
<body>
<?php
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<form method="post" action="<?php echo $PHP_SELF;?>">
<p>Which opportunity do you prefer and why?
<textarea rows="5" cols="20" name="prefer" wrap="physical"></textarea>
<br />
How could you use this opportunity to develop yourself?
<textarea rows="5" cols="20" name="develop" wrap="physical"></textarea>
<br />
What might challenge you?
<textarea rows="5" cols="20" name="challenge" wrap="physical"></textarea>
<br />
</p>
<input type="submit" value="submit" name="submit">
</form>
<?php
} else {
$prefer = $_POST["prefer"];
$develop = $_POST["develop"];
$challenge = $_POST["challenge"];
echo "<p>Which opportunity do you prefer and why?</p> ".$prefer." <br />";
echo "Which opportunity do you prefer and why?<br /> ".$develop." <br />";
echo "Which opportunity do you prefer and why?<br /> ".$challenge." <br /></p>";
}
?>
</body>
</html>

MsCrow

6:22 am on Aug 18, 2006 (gmt 0)

10+ Year Member



Many thanks, it looks much cleaner now. I uploaded the page and whilst I can add the style easier, the output still looks a bit pants. How can I change the script to output to a new page (perhaps) that contains all the style information?

Thank you

[edited by: dreamcatcher at 6:38 am (utc) on Aug. 18, 2006]
[edit reason]
[1][edit reason] No urls as per TOS [webmasterworld.com] Thanks. [/edit]
[/edit][/1]

barns101

10:12 am on Aug 18, 2006 (gmt 0)

10+ Year Member



You could just add the relevant style to the existing page. The reason it probably looks plain is the way that you're displaying it. Play around with the HTML code for the following bit of code, which I have changed a slightly to look more "interesting". Each bit of text now has its own paragraph and the question is highlighted in bold.


<?php
} else {
$prefer = $_POST["prefer"];
$develop = $_POST["develop"];
$challenge = $_POST["challenge"];
echo "<p><b>Which opportunity do you prefer and why?</b></p><p>".$prefer."</p>";
echo "<p><b>Which opportunity do you prefer and why?</b></p><p>".$develop."</p>";
echo "<p><b>Which opportunity do you prefer and why?</b></p><p>".$challenge."</p>";
}
?>

MsCrow

4:52 pm on Aug 18, 2006 (gmt 0)

10+ Year Member



Yay, it's working :-) bare with me, I'm new to this php business having just played with existing code...

I have another question, is it possible to add a print button into the php? I have inserted one that is cross browser compatible but it's not doing anything, or appearing. The link above has the current version, here is the code:

<?php
} else {
$prefer = $_POST["prefer"];
$develop = $_POST["develop"];
$challenge = $_POST["challenge"];
echo "<div id='container'><div id='logo'><img src='images/bannerlogos1.jpg' alt='Blue and white logo for section one' width='475' height='32' /></div>";
echo "<div id='nocolumn'><h2>What is employability?</h2>";
echo "<p><b>Which opportunity do you prefer and why?</b></p><p>".$prefer."</p>";
echo "<p><b>Which opportunity do you prefer and why?</b></p><p>".$develop."</p>";
echo "<p><b>Which opportunity do you prefer and why?</b></p><p>".$challenge."</p>";
echo "<Script Language='Javascript'>function printit(){if (window.print) {window.print(); } else { var WebBrowser = '<object id='WebBrowser1' width=0 height=0 classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'></object>'; document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = ''; }}</script>";
echo "<Script Language='Javascript'> var NS = (navigator.appName == 'Netscape'); var version = parseInt(navigator.appVersion); if (version > 3) { document.write('<form><input type=button value='Print this Page' name='Print' onClick='printit()'></form>'); } </script>";
echo "</div></div>";
}
?>

barns101

5:30 pm on Aug 18, 2006 (gmt 0)

10+ Year Member



The PHP is fine, it's a problem with the JavaScript, probably because it has comments in it and you've put it all on one line. If you leave the original formatting intact it may work.

MsCrow

5:00 pm on Aug 22, 2006 (gmt 0)

10+ Year Member



ok sorted, just have another problem.

Is there a way to force the 'save as' dialogue box across browsers that will save the page as .html rather than php? This is so that the user can save the processed form as open it later.

You can see what I'm trying to do in <removed> and the silly save as javascript is useless.

[edited by: jatar_k at 6:00 pm (utc) on Aug. 22, 2006]
[edit reason]
[1][edit reason] no urls thanks [/edit]
[/edit][/1]