Solved

Adding a POST

Posted on 2013-06-25
15
267 Views
Last Modified: 2013-06-25
I need to add a POST to this script.  The value I am posting is Lid.

<script type="text/javascript">
$(function () {
    $('#popup-wrapper').modalPopLite({
		openButton: '#clicker',
		closeButton: '#close-btn',
		isModal: true });
		});
	</script>

Open in new window


This what it opens.
<div id="popup-wrapper">
		<form name="contactform" method="post" autocomplete="off" action="/Scripts/send_form_email.php">
        <div align="center" >Enter Your E-Mail Address</div><br />
        <div align="center"><input name="ESend" type="text" id"Esend" maxlength="80" size="30"/></div><br />
        <div align="center"><input name="Send" type="submit" value="Submit" /></div><br />
        <div align="center"><input name="Cancel" type="button" id="close-btn" value="Cancel" /></div><br />
        </form>
	</div>

Open in new window

0
Comment
Question by:DS928
[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
  • 7
  • 7
15 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39276108
<script type="text/javascript">
$(function () {

    $('#popup-wrapper').modalPopLite({
		openButton: '#clicker',
		closeButton: '#close-btn',
		isModal: true });

$("input[name='Send']").click(function(evt) {
      evt.preventDefault();
      $.post($(this).attr("action"), $(this).serializeArray());
})


		});
	</script>

Open in new window

0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 39276262
Where is LiD defined?

You have an error in this line
  <div align="center"><input name="ESend" type="text" id"Esend" maxlength="80" size="30"/></div>

Open in new window

You are missing an '=' in your id"Esend" should be id="Esend"

When do you want to POST the LiD value - when the form is submitted or on some other condition?

You can do a post on submit like so - this assumes that the LiD is an input with id="LiD" change as needed or give us more info on your code.
// modify to identify your form if there is more than one on the page
$('form').submit(function() {
   $.post(url, {LiD: $('#lid').val(), function(resp) {
    // if you need to process the response do so here
  });
  // disable default form submission
   return false;
});

Open in new window

0
 

Author Comment

by:DS928
ID: 39276527
Still not passing the value.  If you go to....
http://menuhead.com/bigsearch.php
Select Baltimore/American/Click on Results
Click on 13.5 Winehouse
A new page opens....
Towards the bootom right...Click on Email
A pop up opens
input Email address
Click on submit

This all works, however; the Lid from the restaurantpage.php age is not being passed, so I am getting no info....

This is the Email page. send_form_mail.php

<?php
include("config.php");
$Lid = $_POST['Lid'];
$Lid = mysql_real_escape_string($Lid);  
mysql_query("SET CHARACTER SET utf8");
$sql=mysql_query("SELECT tblRestaurants.RestName,tblLocations.StreetNumber,tblLocations.Street,
	tblLocations.CrossOne, tblLocations.CrossTwo, tblCities.CityName,tblStates.StateName,tblZipCodes.ZipCodeName,
	tblLocations.Phone,tblLocations.Email, tblLocations.Fax, tblLocations.SMS, tblLocations.LocationID
	FROM tblLocations
	INNER JOIN tblRestaurants ON tblRestaurants.RestID = tblLocations.RestID
	INNER JOIN tblCities ON tblCities.CityID = tblLocations.CityID
	INNER JOIN tblStates ON tblStates.StateID = tblLocations.StateID
	INNER JOIN tblZipCodes ON tblZipCodes.ZipCodeID = tblLocations.ZipCodeID
	WHERE tblLocations.LocationID = '$Lid'");
	while($row=mysql_fetch_array($sql))
	{
	$RestName = $row['RestName'];
	$StreetNumber = $row['StreetNumber'];
	$Street = $row['Street'];
	$CrossOne = $row['CrossOne'];
	$CrossTwo = $row['CrossTwo'];
	$City = $row['CityName'];
	$State = $row['StateName'];
	$ZipCode = $row['ZipCodeName'];
	$Phone = $row['Phone'];
	$Email = $row['Email'];
	$Fax = $row['Fax'];
	$SMS = $row['SMS'];
	$Lid = $row['LocationID'];
	}
 
    $to = $_POST['ESend'];
 	$subject = "Menuhead.com";
 	$RestName = $_POST['RestName'];
	$Email = $_POST['Email'];
	$message="
	Name: $RestName \n
	E-mail: $Email \n";
 	$from = "Menuhead";
 	$headers = "From:" . $from;
 	mail($to,$subject,$message,$headers);
 	echo "Mail Sent.";
 ?>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Expert Comment

by:leakim971
ID: 39276582
If LiD is LocationID=1 in your URL, try this :
<script type="text/javascript">
$(function () {

    $('#popup-wrapper').modalPopLite({
		openButton: '#clicker',
		closeButton: '#close-btn',
		isModal: true });

$("input[name='Send']").click(function(evt) {
      evt.preventDefault();
      var LiD = location.search.match(new RegExp("[\\?&]LocationID=([^&#]*)")).pop();
      $.post($("form").attr("action"), {"LiD":LiD, "Esend":$(":text[name='ESend']").val() });
})


		});
	</script>

Open in new window

0
 

Author Comment

by:DS928
ID: 39276614
It's sending the E-Mail but the value of Lid is still not being passed.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39276667
replace : <div align="center"><input name="Send" type="submit" value="Submit" /></div><br />
by :
<div align="center"><input name="Send" type="input" value="Submit" /></div><br />

and remove this line : evt.preventDefault();

<script type="text/javascript">
$(function () {

    $('#popup-wrapper').modalPopLite({
		openButton: '#clicker',
		closeButton: '#close-btn',
		isModal: true });

$("input[name='Send']").click(function(evt) {
      var LiD = location.search.match(new RegExp("[\\?&]LocationID=([^&#]*)")).pop();
      $.post($("form").attr("action"), {"LiD":LiD, "Esend":$(":text[name='ESend']").val() });
})


		});
	</script>

Open in new window


OR

if you want to post your form with the value LiD (alias LocationID)

Don't replace : <div align="center"><input name="Send" type="submit" value="Submit" /></div><br />
But use :
<script type="text/javascript">
$(function () {

    $('#popup-wrapper').modalPopLite({
		openButton: '#clicker',
		closeButton: '#close-btn',
		isModal: true });

$("input[name='Send']").click(function(evt) {
      var LiD = location.search.match(new RegExp("[\\?&]LocationID=([^&#]*)")).pop();
$("form").append("<input type='hidden' name='LiD' value='" + LiD + "' >");
})


		});
	</script>

Open in new window


Yes just use an hidden field : <input type='hidden' name='LiD' value='" + LiD + "' >
You should be able to do that with PHP and put it the value of LocationID inside your tiny form
0
 

Author Comment

by:DS928
ID: 39276698
Mercy, Tried both ways and still not passing the ID.

$(function () {

    $('#popup-wrapper').modalPopLite({
		openButton: '#clicker',
		closeButton: '#close-btn',
		isModal: true });

	$("input[name='Send']").click(function(evt) {
      var Lid = location.search.match(new RegExp("[\\?&]LocationID=([^&#]*)")).pop();
	$("form").append("<input type='hidden' name='Lid' value='" + Lid + "' >");
})

Open in new window


<form name="contactform" method="post" autocomplete="off" action="/Scripts/send_form_email.php">
        <div align="center" >Enter Your E-Mail Address</div><br />
        <div align="center"><input name="ESend" type="text" id="Esend" maxlength="80" size="30"/></div><br />
        <div align="center"><input name="Send" type="submit" id="send" value="Submit" /></div><br />
        <div align="center"><input name="Cancel" type="button" id="close-btn" value="Cancel" /></div><br />
        <input type='hidden' name='Lid' value='" + Lid + "' >
        </form>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 39276721
remove line 6 in the second HTML
0
 

Author Comment

by:DS928
ID: 39276737
Removed Line. Still not passing...
<form name="contactform" method="post" autocomplete="off" action="/Scripts/send_form_email.php">
        <div align="center" >Enter Your E-Mail Address</div><br />
        <div align="center"><input name="ESend" type="text" id="Esend" maxlength="80" size="30"/></div><br />
        <div align="center"><input name="Send" type="submit" id="send" value="Submit" /></div><br />
        <div align="center"><input name="Cancel" type="button" id="close-btn" value="Cancel" /></div><br />
        </form>

Open in new window


$(function () {

    $('#popup-wrapper').modalPopLite({
		openButton: '#clicker',
		closeButton: '#close-btn',
		isModal: true });

	$("input[name='Send']").click(function(evt) {
      var Lid = location.search.match(new RegExp("[\\?&]LocationID=([^&#]*)")).pop();
	$("form").append("<input type='hidden' name='Lid' value='" + Lid + "' >");
})

Open in new window


Is there a way to check if the value Lid is passing once the button is clicked?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39276744
Just checked your code, Lid is passed !

Is there a way to check if the value Lid is passing once the button is clicked?
Your database for example, no?
0
 

Author Comment

by:DS928
ID: 39276751
So if it's passing, then why when I send an email to myself the Name: and Email: are blank.  It should be the name of the Restaurant and their E-Mail address.  Is the problem there?
Or Here?

<?php
include("config.php");
$Lid = $_POST['Lid'];
$Lid = mysql_real_escape_string($Lid);  
mysql_query("SET CHARACTER SET utf8");
$sql=mysql_query("SELECT tblRestaurants.RestName,tblLocations.StreetNumber,tblLocations.Street,
	tblLocations.CrossOne, tblLocations.CrossTwo, tblCities.CityName,tblStates.StateName,tblZipCodes.ZipCodeName,
	tblLocations.Phone,tblLocations.Email, tblLocations.Fax, tblLocations.SMS, tblLocations.LocationID
	FROM tblLocations
	INNER JOIN tblRestaurants ON tblRestaurants.RestID = tblLocations.RestID
	INNER JOIN tblCities ON tblCities.CityID = tblLocations.CityID
	INNER JOIN tblStates ON tblStates.StateID = tblLocations.StateID
	INNER JOIN tblZipCodes ON tblZipCodes.ZipCodeID = tblLocations.ZipCodeID
	WHERE tblLocations.LocationID = '$Lid'");
	while($row=mysql_fetch_array($sql))
	{
	$RestName = $row['RestName'];
	$StreetNumber = $row['StreetNumber'];
	$Street = $row['Street'];
	$CrossOne = $row['CrossOne'];
	$CrossTwo = $row['CrossTwo'];
	$City = $row['CityName'];
	$State = $row['StateName'];
	$ZipCode = $row['ZipCodeName'];
	$Phone = $row['Phone'];
	$Email = $row['Email'];
	$Fax = $row['Fax'];
	$SMS = $row['SMS'];
	$Lid = $row['LocationID'];
	}
 
    $to = $_POST['ESend'];
 	$subject = "Menuhead.com";
 	$RestName = $_POST['RestName'];
	$Email = $_POST['Email'];
	$message="
	Name: $RestName \n
	Emai: $Email \n";
 	$from = "Menuhead";
 	$headers = "From:" . $from;
 	mail($to,$subject,$message,$headers);
 	echo "Mail Sent.";
 ?>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 39276756
to check use a simple send_form_email.php script  :

<?php
       echo "Lid: " . $_POST['Lid'] . "<br />ESend: " . $_POST['ESend'];
?>

Open in new window

0
 

Author Comment

by:DS928
ID: 39276761
Yes, it's returning the value of "1".  So why isn't the message portion displaying when I receive an E-Mail?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39276763
I dunno, it's about PHP now
0
 

Author Comment

by:DS928
ID: 39276766
In all fairness, giving you points and starting a new post.  Thank you very much for your help! I appreciate it.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

695 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