Reply
PHP echo and formatting help
Old 05-12-2008, 10:12 AM PHP echo and formatting help
Novice Talker

Posts: 7
Hi there,

I stumbled on these forums and hope someone can help.

I would like to create a very simple page where users can enter information in text boxes and upload images and then when they click submit the text should be outputted on screen as valid xhtml with each textbox being styled as the script is coded todo

So for instance if the form has

text box : first box text
text box : Second box text
Image: Image

Rendered page

<p style="padding-right: 6px; padding-left: 6px; padding-bottom: 4px; color: #ffffff; padding-top: 2px; background-color: #e26e6e; border: #f6b5b5 2px solid">
<strong>first box text</strong>
</p>
<p style="padding-right: 6px; padding-left: 6px; padding-bottom: 4px; color: #555555; padding-top: 2px; background-color: #f4ff9f; border: #ffe29f 2px solid">
<strong>Second box text</strong><br />
<br />
</p>
<img src="image.jpg" border="0" alt="" width="399" height="299" />


Any help with examples would be appreciated.
Regards
gamma911 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-12-2008, 12:38 PM Re: PHP echo and formatting help
Average Talker

Posts: 28
All of the inputs on the form are accessed by their name using the $_POST variable.

So, if you have something like the following on page1.php:
<form action="page2.php" method="get">
<input type="text" name="txtFieldName">
<input type="submit" value="Send" name="submit">
</form>


Then on page2.php you can output the $_POST variable like:
<?php echo '<p>' . $_POST['txtFieldName'] . '</p>';?>


You can output before/after it whatever you please to make it suit your needs...I wouldn't recommend you hard code in your styles though. I'm hoping you just have that there for testing purposes and will move it to an external CSS file at a later time, when you have the time.

Cheers
Cory Dee is offline
Reply With Quote
View Public Profile
 
Old 05-12-2008, 12:42 PM Re: PHP echo and formatting help
Novice Talker

Posts: 7
Quote:
Originally Posted by Cory Dee View Post
All of the inputs on the form are accessed by their name using the $_POST variable.

So, if you have something like the following on page1.php:
<form action="page2.php" method="get">
<input type="text" name="txtFieldName">
<input type="submit" value="Send" name="submit">
</form>


Then on page2.php you can output the $_POST variable like:
<?php echo '<p>' . $_POST['txtFieldName'] . '</p>';?>


You can output before/after it whatever you please to make it suit your needs...I wouldn't recommend you hard code in your styles though. I'm hoping you just have that there for testing purposes and will move it to an external CSS file at a later time, when you have the time.

Cheers
Thanks for the reply, and point taken on the styles, but unfortunately for this project the styles HAVE to be hard coded due to a separate issue
gamma911 is offline
Reply With Quote
View Public Profile
 
Old 05-21-2008, 09:58 AM Re: PHP echo and formatting help
Novice Talker

Posts: 7
Bumping this, when I use your code it works, but unfortunately the browser interprets the html - I would like the HTML to be outputted in plain text on the screen

Any ideas?
gamma911 is offline
Reply With Quote
View Public Profile
 
Old 05-21-2008, 12:13 PM Re: PHP echo and formatting help
Average Talker

Posts: 28
Which HTML is being interpreted? You're entering HTML into the contents of the input box?
Cory Dee is offline
Reply With Quote
View Public Profile
 
Old 05-21-2008, 12:51 PM Re: PHP echo and formatting help
Novice Talker

Posts: 7
Quote:
Originally Posted by Cory Dee View Post
Which HTML is being interpreted? You're entering
HTML into the contents of the input box?
No the HTML that is being parsed in the php code is being rendered, but this has been solved by encoding the "<" 's

I do have another propblem, I have several text boxes that need different formatting, using your form above how can I add them all and parse all of them?

Another question is, is it possible to show the output as the user is typing?
Guess this would need ajax?
gamma911 is offline
Reply With Quote
View Public Profile
 
Old 05-22-2008, 07:14 AM Re: PHP echo and formatting help
Average Talker

Posts: 28
To display the output as the user is typing, you're right, AJAX would be best. Otherwise, each keystroke would be a page reload and that would be tedious.

To make the form longer, just continue to give the inputs unique names, and they will still be accessible through $_POST...if it's really long, you could even throw it into a loop, just like you would with any other array.
Cory Dee is offline
Reply With Quote
View Public Profile
 
Old 05-22-2008, 07:22 AM Re: PHP echo and formatting help
Novice Talker

Posts: 7
Thanks for the replies so far.

Any Ideas how the AJAX would work ?Im a total beginner with AJAX though..
gamma911 is offline
Reply With Quote
View Public Profile
 
Old 05-22-2008, 02:08 PM Re: PHP echo and formatting help
Average Talker

Posts: 28
Its a fair bit more involved. What exactly is the purpose of outputting their exact input on the same page? It seems a bit redundant, since the text box will already contain their info...
Cory Dee is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP echo and formatting help
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14340 seconds with 12 queries