Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding php variable to a form

Posted on 2013-02-06
5
Medium Priority
?
321 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

670 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