Jump to content

html form with different pre-set value


thankqwerty

Recommended Posts

Hi

I'm a beginner at writing website and everything. I have the following problem.

 

I want to write a very simple page which the users will input their I.P. address using html form. And i can do that with the code below.

 

<form action="update.php" method="post" >
IP: <input type="text" name="IP" >
<input type="submit" value="submit">
</form>

 

Now i want it to have different default value. I know i can set a default value for the input box by :

 

IP: <input type="text" name="IP" value="128.243.0.0">

 

But i don't know how to make the default IP as a variable. For example if i want the default value to be the user's IP. (I know i can get the user's IP with $_SERVER['REMOTE_ADDR']).

Is there any way that i can define a string in php then call it in the input tag?

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/120742-html-form-with-different-pre-set-value/
Share on other sites

Try this....

 

<form action="update.php" method="post" >
IP: <input type="text" name="IP" value="<?php echo $ip=$_SERVER['REMOTE_ADDR']; ?>">
<input type="submit" value="submit">
</form>

 

test example

 

http://www.mesquitechristmas.com/development/form.php

 

Keep in mind your file will need to be .php and not .html

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.