Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,491 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,711 people online right now. Registration is fast and FREE... Join Now!




setting the contents of a form control

 
Reply to this topicStart new topic

setting the contents of a form control

aj32
3 Feb, 2008 - 10:41 AM
Post #1

D.I.C Addict
Group Icon

Joined: 30 Aug, 2007
Posts: 577



Thanked: 2 times
Dream Kudos: 675
My Contributions
Hi all!

Now that I figured out how to save contents of a text box to a file, now I need a way to read in data from a file, parse it, and put the parsed data into text boxes. I no how to parse it and read the file, I just don't have any idea of how to set the value of the control blink.gif .

Thanks for the help! smile.gif
User is offlineProfile CardPM
+Quote Post

Mike007
RE: Setting The Contents Of A Form Control
3 Feb, 2008 - 11:18 AM
Post #2

D.I.C Head
Group Icon

Joined: 30 Aug, 2007
Posts: 205


Dream Kudos: 75
My Contributions
You mean output the values you read to HTML and make it show as a text box?

something like this maybe?
CODE

echo "<input name=\"textbox1\" type=\"text\" value=\"$data\">";

User is offlineProfile CardPM
+Quote Post

aj32
RE: Setting The Contents Of A Form Control
3 Feb, 2008 - 11:22 AM
Post #3

D.I.C Addict
Group Icon

Joined: 30 Aug, 2007
Posts: 577



Thanked: 2 times
Dream Kudos: 675
My Contributions
QUOTE(Mike007 @ 3 Feb, 2008 - 02:18 PM) *

You mean output the values you read to HTML and make it show as a text box?

something like this maybe?
CODE

echo "<input name=\"textbox1\" type=\"text\" value=\"$data\">";



Well, I already have the textboxes there, I just need to set the value of the text boxes after reading the file.

thanx

User is offlineProfile CardPM
+Quote Post

Mike007
RE: Setting The Contents Of A Form Control
3 Feb, 2008 - 11:38 AM
Post #4

D.I.C Head
Group Icon

Joined: 30 Aug, 2007
Posts: 205


Dream Kudos: 75
My Contributions
QUOTE(aj32 @ 3 Feb, 2008 - 12:22 PM) *

QUOTE(Mike007 @ 3 Feb, 2008 - 02:18 PM) *

You mean output the values you read to HTML and make it show as a text box?

something like this maybe?
CODE

echo "<input name=\"textbox1\" type=\"text\" value=\"$data\">";



Well, I already have the textboxes there, I just need to set the value of the text boxes after reading the file.

thanx


The way I see it you have 3 options to do that, although i'm not quite sure why create HTML first and then read the file in PHP, it would make more sense the other way.
But if you don't want to echo the all html thing you can echo only the data like this:
CODE

<input name="textbox1" type="text" value="<?php echo $data; ?>">


That works fine but you have to have your PHP code before that HTML line for it to work.

Another option would be to use javascript to fill those text boxes, and giving the javascript code the data it needs from php, something like
CODE

<script language="JavaScript>
<!--
    document.getElementById("textbox1").value = <?php echo $data; ?>;
-->
</script>


And the last one, my favoriate smile.gif, use smarty template engine (or some other). So that you won't have to worry about HTML at all in your PHP pages, you will just output data to the template and then place it anywhere you want in the template.
http://www.smarty.net

Hope that helps.
User is offlineProfile CardPM
+Quote Post

aj32
RE: Setting The Contents Of A Form Control
3 Feb, 2008 - 01:28 PM
Post #5

D.I.C Addict
Group Icon

Joined: 30 Aug, 2007
Posts: 577



Thanked: 2 times
Dream Kudos: 675
My Contributions
That worked!

thank you! smile.gif
User is offlineProfile CardPM
+Quote Post

Glasseater
RE: Setting The Contents Of A Form Control
3 Feb, 2008 - 06:08 PM
Post #6

New D.I.C Head
*

Joined: 15 Jun, 2007
Posts: 46


My Contributions
Make sure you escape all quotes in your string, just in case. Otherwise it could be used to screw up your html.

This post has been edited by Glasseater: 3 Feb, 2008 - 06:09 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:34PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month