Solved

Adding php variable to a form

Posted on 2013-02-06
5
298 Views
Last Modified: 2013-02-06
Hi all,

I am working on a project that will allow a user to press a button and thier latitude and longitude details are submitted through a form.

I have the lat and long module covered, which I got from www.locationdetection.mobi and I've attached the three files it uses.

Now, here's the problem.

I cannot figure out how to integrate my fotform to grab the latitude and longitude details from the forms.

Here is the form I wish to submit and which will be hopefully embedded into the geo.html page:

<script src="http://jotformpro.com/min/g=jotform?3.1.1502" type="text/javascript"></script>
<script type="text/javascript">
   JotForm.init();
</script>
<link href="http://jotformpro.com/min/g=formCss?3.1.1502" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="http://jotformpro.com/css/styles/nova.css?3.1.1502" />
<style type="text/css">
    .form-label{
        width:150px !important;
    }
    .form-label-left{
        width:150px !important;
    }
    .form-line{
        padding-top:12px;
        padding-bottom:12px;
    }
    .form-label-right{
        width:150px !important;
    }
    .form-all{
        width:690px;
        color:#555 !important;
        font-family:'Lucida Grande';
        font-size:14px;
    }
    .form-radio-item label, .form-checkbox-item label, .form-grading-label, .form-header{
        color:#555;
    }

</style>

<form class="jotform-form" action="http://submit.jotformpro.com/submit/30362045658958/" method="post" name="form_30362045658958" id="30362045658958" accept-charset="utf-8">
  <input type="hidden" name="formID" value="30362045658958" />
  <div class="form-all">
    <ul class="form-section">
      <li class="form-line" id="id_2">
        <div id="cid_2" class="form-input-wide">
          <div style="margin-left:156px" class="form-buttons-wrapper">
            <button id="input_2" type="submit" class="form-submit-button">
              Submit
            </button>
          </div>
        </div>
      </li>
      <li style="display:none">
        Should be Empty:
        <input type="text" name="website" value="" />
      </li>
    </ul>
  </div>
  <input type="hidden" id="simple_spc" name="simple_spc" value="30362045658958" />
  <script type="text/javascript">
  document.getElementById("si" + "mple" + "_spc").value = "30362045658958-30362045658958";
  </script>
  <input type="hidden" class="form-hidden" value="" id="input_4" name="q4_latitude4" />
  <input type="hidden" class="form-hidden" value="" id="input_5" name="q5_longitude" />
</form>

Open in new window




How will I chop and change this around in order to accomplish what I need? If you'd like to see the working demo I have up, please visit here. Please note it will ask you to share your location. I am not tracking/recording any locations on this page - I'm simply using the supplied three files below.

Thanks in advance for your help with this.
geo.html
geo.js
geo.php
0
Comment
Question by:oconnork00
  • 3
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 38858905
First get the lat and long values into a php variable such as $lat and $long.

Then (in html) put them into the form using this

<input type=hidden name=lat value=<?php  echo $lat; ?>'>
<input type=hidden name=long value=<?php  echo $long; ?>'>

In the action script, you retrieve hidden inputs the same as any other, for example in Post,

$lat = $_POST["lat"];
0
 
LVL 2

Author Comment

by:oconnork00
ID: 38858938
Thanks yodercm,

Here's the new page

Unfortunately it's not bringing in the date I need. Here's the code I edited (your part suggested is at the bottom):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="Andy Moore: http://locationdetection.mobi/">
  <title>Location Detection Example</title>
  </head>
  <body>
	  <h1>Accept Browser Location Detection</h1>
		<div id="geo" class="geolocation_data"></div>
		<script type="text/JavaScript" src="geo.js"></script>
  </body>
</html>
<script src="http://jotformpro.com/min/g=jotform?3.1.1502" type="text/javascript"></script>
<script type="text/javascript">
   JotForm.init();
</script>
<link href="http://jotformpro.com/min/g=formCss?3.1.1502" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="http://jotformpro.com/css/styles/nova.css?3.1.1502" />
<style type="text/css">
    .form-label{
        width:150px !important;
    }
    .form-label-left{
        width:150px !important;
    }
    .form-line{
        padding-top:12px;
        padding-bottom:12px;
    }
    .form-label-right{
        width:150px !important;
    }
    .form-all{
        width:690px;
        color:#555 !important;
        font-family:'Lucida Grande';
        font-size:14px;
    }
    .form-radio-item label, .form-checkbox-item label, .form-grading-label, .form-header{
        color:#555;
    }

</style>

<form class="jotform-form" action="http://submit.jotformpro.com/submit/30362045658958/" method="post" name="form_30362045658958" id="30362045658958" accept-charset="utf-8">
  <input type="hidden" name="formID" value="30362045658958" />
  <div class="form-all">
    <ul class="form-section">
      <li class="form-line" id="id_2">
        <div id="cid_2" class="form-input-wide">
          <div style="margin-left:156px" class="form-buttons-wrapper">
            <button id="input_2" type="submit" class="form-submit-button">
              Submit
            </button>
          </div>
        </div>
      </li>
      <li style="display:none">
        Should be Empty:
        <input type="text" name="website" value="" />
      </li>
    </ul>
  </div>
  <input type="hidden" id="simple_spc" name="simple_spc" value="30362045658958" />
  <script type="text/javascript">
  document.getElementById("si" + "mple" + "_spc").value = "30362045658958-30362045658958";
  </script>
<input type=hidden name=lat value=<?php  echo $lat; ?>'>
<input type=hidden name=long value=<?php  echo $long; ?>'>

</form>

Open in new window


Do I need to wait for it to load? Is it even in the right place?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 38859045
Date?  What date?
0
 
LVL 2

Author Comment

by:oconnork00
ID: 38859105
Sorry, meant data.

Got it working now, thanks for the help yodercm
0
 
LVL 27

Expert Comment

by:yodercm
ID: 38859222
Oh, I see, ok, glad you got it working :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now