How my ip address will come automatically in a texbox [duplicate] - html

This question already has answers here:
Get client IP address via third party web service
(7 answers)
Closed 8 years ago.
I have a textbox in a page call enquiry.
i want when my page loads my ip address will come automatically in that texbox... please help me..i need your suggestions as soon as possible .

What language are you using (server-side)?
If you want to do this in PHP, here's how:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
?>
<form>
<!-- other form elements here -->
<input type="text" name="ip" value="<?php if isset($ip) { echo $ip; } ?>" />
</form>
The first part gets the users IP address. The second part prints its value in the text field.

You want your users to see their ip address in a text box?
Assuming you have to do it on the client-side, you need to use javacript. Like this (taken from How to get client's IP address using javascript only?):
<script type="application/javascript">
function getip(json){
alert(json.ip); // alerts the ip address
// instead of the alert, assign the value to your text box
}
</script>
<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>

Related

Simple cross domain form posting not working (whmcs)

I am trying to get a search box to post its content into a searchbox on another domain, using the html post method, however its not working after being redirected to the second site the search box remains empty on site 2.
Both servers belong to the same business and I have access to both, can someone tell me what I could do without using java to get the contents from the input box 1 on site 1 posted to the input box 2 on site 2
here is the line of code I am using on the first site.
form action="https://site2.com/cart.php?a=add&domain" method="post"
Thanks
You''ll need to catch and process both the GET arguments (in your action URL) and the POST stream (from the form elements) in the site2.com/cart.php file that you are using as the action.
Assuming the input box on site1 is named inputBox and is contained in the form with that action, when the form is submitted the site2.com/cart.php script can access the value at $_POST['inputBox'] - ie, wherever that goes on site2, you could do
<form name="someformonsite2" action="....">
<input type=text
<?php
if((!empty($_POST['inputBox'])&&(passes_your_validation($_POST['inputBox']))){
print("value=\"".$_POST['inputBox']."" );
}
?>
size=12 maxlength=11>
<!-- rest of form follows -->
Which would effectively send to the browser:
<input type=text value="SomeVal" size=12 maxlength=11>

Ethernet shield: sending data from web to arduino using html form [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have already completed the controlling of devices through internet using buttons. I used Arduino Uno+ SD CARD+ Ethernet shield. Now I want to modify it so that used can send text commands through form submission to control the same.
I could do it when I was using the Arduino Uno Memory for HTML code but now facing problems when I am using SD Card for HTML. Expecting the code module for the same.
Yes, it's possible. But you'll need to use a web socket. I've done that using PHP.
So, you'll create a page with html and php that, when you click on the submit button, will send the commands. It must be like that, in php:
<?php
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($sock,"ip number of arduino", 8080);
$messsage = '0';
if (isset($_POST['on'])){
$msg='1';
}
if (isset($_POST['off'])){
$msg='0';
}
socket_write($sock, $msg);
?>
So you just need to write a html to send the post method when a form be submited.
Submission of HTML form actually invokes POST or GET method of HTTP protocol. This protocol is human readable.
Example of HTTP request from w3schools :
POST /test/demo_form.asp HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2
This is what you'll get into arduino buffer. You can simply search for name1= pattern and read the value and act accordingly.
In the example below I read values of variables s and e.
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) {
bfill = ether.tcpOffset();
char* socket = strstr((char *)Ethernet::buffer + pos, "?s=");
if(socket != 0){
byte s = getIntArg(socket, "s");
byte e = getIntArg(socket, "e");
Serial.println("Request");
Serial.println(s);
Serial.println(e);
PlanActions(s, e)
}
Form for this request looks like:
<form action="." method="POST">
<select name="s" size="1">
<option value="0">TV</option>
<option value="1">HiFi</option>
</select>
<input name="e" type="submit" value="0">
<input name="e" type="submit" value="1">
</form>
In the example I'm sending simple form page from arduino, but you can have the page wherever you want. It can be on local computer or web server. Just change action to something like <form action="arduino-ip"

How to save form data when going to another page

I have a simple application form it is divided in 3 pages. What I want is when i fill up the 1st page, then when i go to another page the data is still there so I co go back to first page when I want to changes the data I inputted.
I tried saving it in session but I think that is not the right way to do it. any suggestions?
As you post the page, set the values you post in session variables
e.g.
<?php $_SESSION['name'] = $_POST['name']; ?>
Then in your input fields, check to see if the session is set & if so they display that.
e.g.
<input type="text" name="name" value="<?php if (isset($_SESSION['name'])) { echo $_SESSION['name']; } " />
Make sure you start a session on each page you want to use them on!
<?php start_session; ?>

Simple html5 voting system

Some time ago I created a simple Cocoa (OSX) app with 5 buttons allowing the user to vote for one of 5 options. When a button is clicked, the app gives some feedback about what button is clicked, thanks the user for his/her vote and goes back to the initial state to allow for the next voter. The votes were written to a simple text file to be retrieved after all the votes were cast. Very simple but OK for its purposes (a fancy way to vote for a class representative at my daughters school).
Now I'm asked to develop the same system for a web browser using html5. The school wants the setup to run on more than one computer at the same time. So we have a local server and two or three computers connected to it. The data from the votes needs to be written to the server.
Can someone point me in the right direction of an example that already does this? I found some voting systems but they all work with radio buttons or checkboxes, I need 5 large graphics (animated if possible) on an (also animated) background. I assume it's all very simple to the seasoned HTML5 editor, but I'm a beginner.
Okay, you mentioned you are a 'beginner' (FYI, I'm not a professional developer either), but I assume you know what forms are and how they work. The below is super-simple, I won't even use AJAX. (Explanation in comments.)
The code is going to be in one file. You mentioned PHP, so I assume you can use that. It's what I am using below:
<?
if (isset($_POST['vote'])) { // Check if there is a vote POSTed to our page
// Store the vote. I don't know how you did it the previous time, I'm just going to write it to a text file
$file = fopen("votes.txt", "w");
fwrite($file, $_POST['vote']);
fclose($file);
}
?>
<!-- the voting page -->
<HTML>
<HEAD>
<title>Vote</title>
</HEAD>
<BODY>
<!-- Create a form to be able to send the vote to the server in the simplest way, but don't display it -->
<form action="thispage.html" method="post" style="display:none;">
<!-- I don't know what possible values there are. I'll just take 'foo' and 'bar'. Of course you can add more. -->
<input type="radio" name="vote" value="foo" />
<input type="radio" name="vote" value="bar" />
</form>
<!-- The images representing the (invisible) radio button -->
<!-- I use the data-value attribute to store to which radio button this image corresponds -->
<img src="path/to/foo/image" data-value="foo" />Vote FOO<br />
<img src="path/to/bar/image" data-value="bar" />Vote BAR<br />
<!-- Import jQuery for the sake of simplicity. -->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<!-- The trickiest part. The script. -->
<script>
$("img").click(function() {
var value = $(this).data('value'); // Get the value
$("input[value='" + value + "']").click();// Click the corresponding radio button
$("form").submit(); // Submit the form.
});
</script>
</BODY>
</HTML>
NOT TESTED.

Create a link that automatically fills a field on the target page

I'm coding a newsletter and the guy that asked me to do it wants a link in it...all perfect no problems...
Now the problem is that when you click on this link it goes on a page with fields and the guy asked me if it's possible to automatically fill up one of the fields.
The page is a subscription page for some services and this guy wants me to fill up the referral field automatically when you land on the page with his email. Is it possible?
Thanks heaps
One way to do this is to place the field name and value in the query string. The "query string" is the part of a URL which contains field/value pairs. It is separated from the page address by a ? followed by field=value pairs separated by & characters. For example,
http://www.example.com
...would become...
http://www.example.com?fieldName=fieldValue
In order for this to work, the page must parse the field as part of the HTTP GET request and then return the value as a pre-filled field. If the form is properly validated at the server side then it usually already has this capability of parsing fields and retaining their values across multiple submissions of the same form. This is because doing so allows the page to be redrawn with an error message if some fields are blank or have invalid values.
This is very easy to test - just find the field name in the page source and extend the URL you are currently using as shown above. If it works you are done. If not, you may need to get the code on the server side updated to accept the field as part of the query string.
Other ways to accomplish the same thing are more dependent on the server-side code. For example, many sites embed the associate referral ID in the URL such as:
http://www.example.com/123456/
In this case, server-side code interprets the directory path as a field and parses it accordingly. Because this requires very specific server-side code to support it, the first option is probably your best bet.
Encountered this issue, and the following Javascript code did the trick.
Using #T.Rob query string parameters.
HTML CODE:
<input type="text" name="fillfield" id="fillfield" style="width: 350px;" class="input" value=""/>
JAVASCRIPT CODE:
window.onload=function(){
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}
var fieldName = querySt("fieldName");
if( fieldName==null){
}else{
document.getElementById('fillfield').value = fieldName;
}
}
When you visit http://www.example.com?fieldName=fieldValue it would automatically fill in fieldValue to the fillfield input.
Using php
<?
$passthis = "See you on the other side";
echo '<form action="whereyouwantittogo.php" target="_blank" method="post">'.
'<input type="text" name="passthis1" value="'.
$passthis .' " /> '.
'<button type="Submit" value="Submit" >Submit</button>'.
'</form>';
?>
The script for the page you would like to pass the info to:
<?
$thispassed = $_POST['passthis1'];
echo '<textarea>'. $thispassed .'</textarea>';
echo $thispassed;
?>
Use this two codes on seperate pages with the latter at whereyouwantittogo.php and you should be in business.