Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Auto enter text in html field with php
Old 02-15-2008, 04:20 PM Auto enter text in html field with php
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Hi

i have a php file that calls an html file

in the html file it calls, there is a field called username

how can i autoput a username in that from the php its inside?

the name will change so i can't just add it manually to the html file

any help would be grate thanks

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-15-2008, 05:25 PM Re: Auto enter text in html field with php
Mattmaul1992's Avatar
Ultra Talker

Posts: 486
Name: Matt
Trades: -1
You'd have to use AJAX if both pages are separate. Better yet you can merge the files. That's what you really should do. It allows you to do more easier and saves a bit of disk space along the way.. An example would be the situation you're having right now lol. AJAX is becoming quit common thanks to "Web 2.0" so I suggest learning it either way.
http://www.w3schools.com/ajax
__________________
PHP Code:
$talkupation++; 

Please login or register to view this content. Registration is FREE
- Free IPB forum hosting (releasing today!!!), no ads, free modifications
Mattmaul1992 is offline
Reply With Quote
View Public Profile
 
Old 02-15-2008, 06:07 PM Re: Auto enter text in html field with php
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
no, there not separate..

the html is called by the php with include..

i know there is a way round it without the ajax as ajax hasn't been around all that long yet this has

i have a php file with a username in it as a varible

the php file calls the html with

include( "sendmessage.html" );

and the username field that comes with the html file has a field in it for the username

and i want the username taking from the variable and adding to the username field in the html that is included
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-15-2008, 06:22 PM Re: Auto enter text in html field with php
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
just figured it out, i can use the same was as i have with smilies, just add the text to the field with javascript

thanks for your help

Sharon x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-15-2008, 10:25 PM Re: Auto enter text in html field with php
Mattmaul1992's Avatar
Ultra Talker

Posts: 486
Name: Matt
Trades: -1
Lol sorry I misread your question.. Maybe sleep is a good thing after all :S.
__________________
PHP Code:
$talkupation++; 

Please login or register to view this content. Registration is FREE
- Free IPB forum hosting (releasing today!!!), no ads, free modifications
Mattmaul1992 is offline
Reply With Quote
View Public Profile
 
Old 02-16-2008, 03:14 AM Re: Auto enter text in html field with php
rion's Avatar
Experienced Talker

Posts: 31
Name: Rion
Location: Portland, Oregon
Trades: 0
you can use javascript...but if your user has javascript disabled that solution (obviously) won't work... here is another solution (untested but should be close to working)


PHP Code:
$username $_POST['username']; //or $_GET['username'] or whichever method
$file_name 'sendmessage.html';
$file_contents file_get_contents($file_name);
$output str_replace('{username}',$username,$file_contents);
echo 
$output

in your html file you would do something like this in your form
HTML Code:
<input type="text" name="username" id="username" value="{username}">
The curly {} bracketed username would be replaced by the username. You could mod this a bit to handle the circumstance if a username is not provided.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
rion is offline
Reply With Quote
View Public Profile Visit rion's homepage!
 
Old 02-16-2008, 08:31 AM Re: Auto enter text in html field with php
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Quote:
Originally Posted by rion View Post
you can use javascript...but if your user has javascript disabled that solution (obviously) won't work... here is another solution (untested but should be close to working)


PHP Code:
$username $_POST['username']; //or $_GET['username'] or whichever method
$file_name 'sendmessage.html';
$file_contents file_get_contents($file_name);
$output str_replace('{username}',$username,$file_contents);
echo 
$output

in your html file you would do something like this in your form
HTML Code:
<input type="text" name="username" id="username" value="{username}">
The curly {} bracketed username would be replaced by the username. You could mod this a bit to handle the circumstance if a username is not provided.
Now that works a treat

thanks for that, much better than my method.

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Auto enter text in html field with php
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.25827 seconds with 12 queries