caveat: this would probably be pretty simple with a submit, but because of someone else's #%^$!& code, every submit clears all data on all forms on the page, so i cannot use .submit()
here's what i'm trying to do:
step 1: a link on a page, via Javascript, opens a popup. that popup has a some fields you fill it out, and using window.opener.getElementById('hiddenX').value, various hidden html elements on the original page are then updated, and the popup is closed.
step 2: on unload of the popup, the html elements are modified via Javascript.
step 3: the updated html elements are added back to $_POST on the page
Step 4: a bit of php code runs a php function using the values from $_POST as well as the values produced by earlier php code to create and send an email.
I do not think i can pass the values via a GET-style url since some of the values are very very long text strings, and tehre will probably be some arrays as well. I have tried using .post(window.location, {val1 : "1stvalue"}) in combination with a .load() on the div containing the php code from step 4. i think the div updates, but the POST value remains empty. any ideas?
script:
$(".email1").on('click', function (event) {
var win1 = window.open("../sub1.php","_blank","height=450,width=510, status=yes,toolbar=no,menubar=no,location=no");
$(win1).on('unload', function (event){
if(document.getElementById('hidden1').value != "z"){
$tosend2 = document.getElementById('hidden3').value;
...... // various changes to $tosend2 and other elements on the page
$.post( window.location, { hidden3 : "abc" }); //temporarily use "abc" instead of $tosend2
$( "#emaildiv" ).load(location.href+" #emaildiv2>*","" );
}
});
});
html / php :
<div style="display : hidden" name="emaildiv" id="emaildiv">
<input type="hidden" name="hidden1" id="hidden1" value="z" />
<input type="hidden" name="hidden3" id="hidden3" value="z" />
</div>
<div style="display : hidden" name="emaildiv2" id="emaildiv2">
<?php
echo "<div class='error'> what is the val?: " . $_POST['hidden1'] . " </code></div>";
if( !empty($_POST['hidden1']) ){
if( $_POST['hidden1'] != "z" ){
echo "<div class='error'> what is it now?: " . $_POST['hidden1'] . " </code></div>";
//emailstuff($locnlist, $_POST['hidden1'], $_POST['hidden3']);
//echo "email sent";
}
}
?>
</div>
I solved this by moving the email function and php div to a separate php page, called sub2.php, and then sending the post values to that page via ajax
$.ajax({
type: 'post',
url: '/routing/sub2.php' ,
data: { hidden1 : document.getElementById('hidden1').value ,
hidden2 : document.getElementById('hidden2').value ,
hidden4 : document.getElementById('hidden4').value ,
locnlist : loclist },
success: function () {
alert("Email has been sent!");
}
});
this doesn't actually solve the initial issue, but it works just as well. if someone has a better solution, i'd be very pleased to know what it is