Solved

Adding a POST

Posted on 2013-06-25
15
221 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
  • 7
  • 7
15 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
<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 51

Expert Comment

by:Julian Hansen
Comment Utility
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
Comment Utility
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
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 82

Expert Comment

by:leakim971
Comment Utility
remove line 6 in the second HTML
0
 

Author Comment

by:DS928
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I dunno, it's about PHP now
0
 

Author Comment

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

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

16 Experts available now in Live!

Get 1:1 Help Now