Add numerical value to variable, and then be able to add further values to it

After sending the mail you need to echo back one value to your JS. Something like:

echo $result;

Should do it.

If not, add:

console.log(html);

to your JS and post the output.

Ideally, you should also tidy up your PHP file a bit to make it more obvious what is being called where.

Tut, I dont know what i just did then, but it seems to be working now…

So i get the alert ‘Good’ back now instead of the other error, and so rather than the alert message, i need to now try and bring out fancybox

Exactly. You need to trigger FancyBox programatically from within your success callback.

Ok I got it sorted to some extent, but it doesnt seem right.

Is it usual that you cant click the outside area to close fancybox down…

http://devchecksafetyfirst.csf.dcmanaged.com/Adam/complete.php

Normally a click on the overlay will close the fancybox.
Is this what you would like?

yes i suppose so, was just thinking though that they may accidently close it down if they click outside it, it would be better to have the little close cross in the top right corner of the central div area.

Also how do I clear the values from the form once its clear we got success.

Got the form bit sorted -

$(‘#formMain’)[0].reset();

Am going to look into the paypal bit now, and try and get the values into it

Hi Pullo,

Got quite a lot done today which was very suprising, but am struggling to get some details out of the form and into the paypal form.

here is the form


<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_BLANK">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="<?=$paypal?>" />
<input type="hidden" name="item_name" value="ITEM NAME" />
<input type="hidden" name="custom" value="CUSTOM VALUE" />
<input type="hidden" name="item_number" value="ITEM NUMBER" />
<input type="hidden" name="amount" value="<?=$_SESSION['totalHidden']?>" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="lc" value="GB" />
<input type="hidden" name="bn" value="PP-BuyNowBF" />
<input src="images/paypal_Buy.png" name="Submit" type="image" value="pruchase" alt="Purchase" />
</form>

Have used a session value from the previous screen as the total and that works fine, but I think because the page doesnt refresh I dont know how to get the first name and surname and other details out of that form and into the paypal form,

Oh dont worry Pullo,

Sorry to keep bothering you I will work it out tonight, a bit tired now sorry.

Thanks

Morning,

So how are things looking?
You made several posts in a row between last night and now and I’m not sure what the current question is :slight_smile:

Morning Pullo,

Well basically I got to the point yesterday where I have it all pretty much connected up, but one very annoying problem is that the details the user puts in the form I cant get the first name etc to go with the paypal button for it, rather when the paypal button is clicked its using the name from the previous entry, from what I can see after entering the details into the form, and then it going to process.php the page needs to refresh before FancyBox opens so that the details from that form become relevant.

This is the paypal form


<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_BLANK">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="<?=$paypal?>" />
<input type="hidden" name="item_name" value="<?=$_SESSION['name']?>" />
<input type="hidden" name="custom" value="CUSTOM VALUE" />
<input type="hidden" name="item_number" value="ITEM NUMBER" />
<input type="hidden" name="amount" value="<?=$_SESSION['totalHidden']?>" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="lc" value="GB" />
<input type="hidden" name="bn" value="PP-BuyNowBF" />
<input src="images/paypal_Buy.png" name="Submit" type="image" value="pruchase" alt="Purchase" />
</form>

amount works perfectly, as the session variable is holding that from the previous page, so no trouble there its the item_name field where the problem lies.

When it goes to process.php to do its bit I am capturing some of the details in session variables


$fname = ($_GET['Fname']) ? $_GET['Fname'] : $_POST['Fname'];
$sname = ($_GET['Sname']) ? $_GET['Sname'] : $_POST['Sname'];
$email = ($_GET['Email']) ? $_GET['Email'] : $_POST['Email'];
$telephone = ($_GET['Telephone']) ?$_GET['Telephone'] : $_POST['Telephone'];
$message = ($_GET['Message']) ?$_GET['Message'] : $_POST['Message'];

$_SESSION['name'] = $fname;
$_SESSION['surname'] = $sname;
$_SESSION['telephone'] = $telephone;


Then it returns to complete.php when its a success and it clears the form and calls fancybox


success: function (html) {              

 if (html==1) {
$('#formMain')[0].reset();
$.fancybox({
content: $('#access-policy'),
modal: true
});
return false;
} else alert('Sorry, unexpected error. Please try again later.');               
 }       


But before fancybox is called it seems to me that complete.php needs to refresh so the right session variables work at the right time.

Oh ok, could you post your current JS which is making the AJAX request?

Thanks Pullo,


<script>
$(document).ready(function() {
//if submit button is clicked
$('#submit').click(function () {        
//Get the data from all the fields
var fname = $('input[name=FName]');
var sname = $('input[name=SName]');
var email = $('input[name=Email]');
var telephone = $('input[name=Telephone]');
var message = $('textarea[name=Message]');
  
//Simple validation to make sure user entered something
if (fname.val()=='') {
   alert ("Please add your first name");
   return false;
}
if (sname.val()=='') {
   alert ("Please add your surname");
   return false;
}
if (email.val()=='') {
   alert ("Please add your email address");
   return false;
}
if (telephone.val()=='') {
   alert ("Please add your telephone number");
   return false;
}
//organize the data
var data = 'Fname=' + fname.val() + '&Sname=' + sname.val() + '&Email=' + email.val() + '&Telephone=' + telephone.val() + '&Message='  + message.val();
//disabled all the text fields
$('.text').attr('enabled','false');

//show the loading sign
$('.loading').show();

//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "process.php",
 
//POST method is used
type: "GET",

//pass the data         
data: data,
     
//Do not cache the page
 cache: false,

//success
success: function (html) {              

 if (html==1) {
 $('#formMain')[0].reset();
 $.fancybox({
 content: $('#access-policy'),
 modal: true
 });
 return false;

 } else alert('Sorry, unexpected error. Please try again later.');               
}       
});

//cancel the submit button default behaviours
return false;
}); 
}); 
</script>

<script type="text/javascript">
 $(document).ready(function() {
  $(".fancybox").fancybox();
 });
</script>


I think you know whats happening, you can try it for yourself as you know, but basically if I come to the page first and enter John davies and then click the PayPal button no name will appear, then i go back to it after its refreshed and this time put Michael Sheen in and click the paypal button, it will be John Davies and so on.

At the top of your script you have this:

var fname = $('input[name=FName]');

so unless I’m missing something, this variably should be available to you in your FancyBox content.

ah…

Yes, I think I sort of went the other way to session variables as wasnt sure of getting var values into a html form.

I used:


var fname = $('input[name=FName]');
var sname = $('input[name=SName]');
var email = $('input[name=Email]');
var telephone = $('input[name=Telephone]');
var message = $('textarea[name=Message]');

document.getElementById('namePay').value = fname;


to populate


<input type="hidden" id="namePay" name="item_name" value="" />

and didnt get a result, would the paypal form need to be below the ajax script.

Not if you’re doing this from within your success callback (which I presume you are).

Try this:

//success
success: function (html) {              
  console.log(fname);
  ...
});

just to make sure you do have a reference to the value.

What is output to the console?

Didnt get a result, in fact on double checking fancyBox doesnt open at all now, used:


success: function (html) {              

if (html==1) {
console.log(fname);
document.getElementById('namePay').value = fname;
$('#formMain')[0].reset();
    
$.fancybox({
content: $('#access-policy'),
modal: true
});
return false;                
}


Oh dear.

Well, remove everything else, just so we can see if we have a reference to fname:

success: function (html) {              
  console.log("In success callback");
  console.log(fname);             
}

What is logged to the console in this case (don’t worry about fancybox for the moment).

Hi Pullo,

Nothing happened when I put the code below in, just so that I know, am i to expect a sort of alert pop up.


success: function (html) {              
if (html==1) {
console.log("In success callback");
console.log(fname);    

}
                }


Also nothing from :


success: function (html) {              
   console.log("In success callback");
   console.log(fname);    
 }