Solved

Adding php variable to a form

Posted on 2013-02-06
5
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
Cornelia Yoder 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:Cornelia Yoder
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:Cornelia Yoder
ID: 38859222
Oh, I see, ok, glad you got it working :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

739 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