Form passing variables but not their entered values












0















I have inherited some broken code but I'm not sure where the problem is. The code is a hyperlink (.control_button) which opens a form(#convert-form) in a lightbox . This then has a button (#print-button) which redirects to a php file (convert-tpl.php), passing fields from the form.



Using XDebug I can see that the variable 'testVariable' is in the $_GET array when it is passed to convert-tpl.php, but it is always set to 10, even when I change it to something else. My guess is that this is because the jQuery code is building the URL with the parameters when the page loads, so it doesn't pick up any entries in the form?



<div class="control_button"><a href="#convert-form" class="convert-link">Terms &amp; Conditions Print</a></div>

<div id="convert-form" style="display:none;">
<h2>Print Terms &amp; Conditions</h2>
<p>Fill out the form below to populate additional information in the terms and condition form. Then hit print to print a copy of the terms and conditions</p>
<form action="phpscripts/convert.tpl" method="get" target="_blank">
<input type="hidden" name="instructor_id" value="<?php echo $_SESSION['USER_ID']; ?>" />
<input type="hidden" name="student_id" value="<?php echo $_GET['id']; ?>" />
<div class="price-details left">
<fieldset>
<legend>Price Details</legend>
<div class="input-box">
<label for="prices_hour">1 Hour:</label><br />
<input type="text" name="testVariable" value="10"/>
</div>
</fieldset>
</div>
<div class="button-container">
<a id="print-button" href="phpscripts/convert-tpl.php" class="big-button button-link">Print</a>
</div>
</form>
</div>


<script type="text/javascript">
$(document).ready(function() {
$(".convert-link").fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none'
});
jQuery('#print-button').printPage({
url: jQuery('#print-button').attr('href')+'?'+jQuery('#convert-form form').serialize()
});
});
</script>









share|improve this question


















  • 1





    Try wrapping your jQuery('#print-button').printPage({...}) with a jQuery('#print-button').on(‘click’, function(){…}), so that it doesn’t serialize() your form until you click print

    – Sean
    Jan 18 at 14:25






  • 1





    That URL gets generated straight on away on page load, which is why only the default value is used. You need to rebuild the code to build the URL when you press the button instead.

    – Magnus Eriksson
    Jan 18 at 14:25













  • I say that value of testVariable is plain static html. There is definetly some code missing, that is needed to successfully update testVariable on say page reload. And the problem it's not just building url the correct way.

    – Eugene Anisiutkin
    Jan 18 at 14:28













  • I think I'm almost there. I changed the jQuery code to the following and it is passing the variable. Now the only problem is that the #print-button needs to be pressed twice. My issue is that I don't really understand what printPage() is doing: jQuery('#print-button').on('click', function(){ jQuery('#print-button').printPage({ url: 'phpscripts/convert-tpl.php?'+jQuery('#convert-form form').serialize() }); });

    – alex rees
    Jan 18 at 14:59


















0















I have inherited some broken code but I'm not sure where the problem is. The code is a hyperlink (.control_button) which opens a form(#convert-form) in a lightbox . This then has a button (#print-button) which redirects to a php file (convert-tpl.php), passing fields from the form.



Using XDebug I can see that the variable 'testVariable' is in the $_GET array when it is passed to convert-tpl.php, but it is always set to 10, even when I change it to something else. My guess is that this is because the jQuery code is building the URL with the parameters when the page loads, so it doesn't pick up any entries in the form?



<div class="control_button"><a href="#convert-form" class="convert-link">Terms &amp; Conditions Print</a></div>

<div id="convert-form" style="display:none;">
<h2>Print Terms &amp; Conditions</h2>
<p>Fill out the form below to populate additional information in the terms and condition form. Then hit print to print a copy of the terms and conditions</p>
<form action="phpscripts/convert.tpl" method="get" target="_blank">
<input type="hidden" name="instructor_id" value="<?php echo $_SESSION['USER_ID']; ?>" />
<input type="hidden" name="student_id" value="<?php echo $_GET['id']; ?>" />
<div class="price-details left">
<fieldset>
<legend>Price Details</legend>
<div class="input-box">
<label for="prices_hour">1 Hour:</label><br />
<input type="text" name="testVariable" value="10"/>
</div>
</fieldset>
</div>
<div class="button-container">
<a id="print-button" href="phpscripts/convert-tpl.php" class="big-button button-link">Print</a>
</div>
</form>
</div>


<script type="text/javascript">
$(document).ready(function() {
$(".convert-link").fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none'
});
jQuery('#print-button').printPage({
url: jQuery('#print-button').attr('href')+'?'+jQuery('#convert-form form').serialize()
});
});
</script>









share|improve this question


















  • 1





    Try wrapping your jQuery('#print-button').printPage({...}) with a jQuery('#print-button').on(‘click’, function(){…}), so that it doesn’t serialize() your form until you click print

    – Sean
    Jan 18 at 14:25






  • 1





    That URL gets generated straight on away on page load, which is why only the default value is used. You need to rebuild the code to build the URL when you press the button instead.

    – Magnus Eriksson
    Jan 18 at 14:25













  • I say that value of testVariable is plain static html. There is definetly some code missing, that is needed to successfully update testVariable on say page reload. And the problem it's not just building url the correct way.

    – Eugene Anisiutkin
    Jan 18 at 14:28













  • I think I'm almost there. I changed the jQuery code to the following and it is passing the variable. Now the only problem is that the #print-button needs to be pressed twice. My issue is that I don't really understand what printPage() is doing: jQuery('#print-button').on('click', function(){ jQuery('#print-button').printPage({ url: 'phpscripts/convert-tpl.php?'+jQuery('#convert-form form').serialize() }); });

    – alex rees
    Jan 18 at 14:59
















0












0








0








I have inherited some broken code but I'm not sure where the problem is. The code is a hyperlink (.control_button) which opens a form(#convert-form) in a lightbox . This then has a button (#print-button) which redirects to a php file (convert-tpl.php), passing fields from the form.



Using XDebug I can see that the variable 'testVariable' is in the $_GET array when it is passed to convert-tpl.php, but it is always set to 10, even when I change it to something else. My guess is that this is because the jQuery code is building the URL with the parameters when the page loads, so it doesn't pick up any entries in the form?



<div class="control_button"><a href="#convert-form" class="convert-link">Terms &amp; Conditions Print</a></div>

<div id="convert-form" style="display:none;">
<h2>Print Terms &amp; Conditions</h2>
<p>Fill out the form below to populate additional information in the terms and condition form. Then hit print to print a copy of the terms and conditions</p>
<form action="phpscripts/convert.tpl" method="get" target="_blank">
<input type="hidden" name="instructor_id" value="<?php echo $_SESSION['USER_ID']; ?>" />
<input type="hidden" name="student_id" value="<?php echo $_GET['id']; ?>" />
<div class="price-details left">
<fieldset>
<legend>Price Details</legend>
<div class="input-box">
<label for="prices_hour">1 Hour:</label><br />
<input type="text" name="testVariable" value="10"/>
</div>
</fieldset>
</div>
<div class="button-container">
<a id="print-button" href="phpscripts/convert-tpl.php" class="big-button button-link">Print</a>
</div>
</form>
</div>


<script type="text/javascript">
$(document).ready(function() {
$(".convert-link").fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none'
});
jQuery('#print-button').printPage({
url: jQuery('#print-button').attr('href')+'?'+jQuery('#convert-form form').serialize()
});
});
</script>









share|improve this question














I have inherited some broken code but I'm not sure where the problem is. The code is a hyperlink (.control_button) which opens a form(#convert-form) in a lightbox . This then has a button (#print-button) which redirects to a php file (convert-tpl.php), passing fields from the form.



Using XDebug I can see that the variable 'testVariable' is in the $_GET array when it is passed to convert-tpl.php, but it is always set to 10, even when I change it to something else. My guess is that this is because the jQuery code is building the URL with the parameters when the page loads, so it doesn't pick up any entries in the form?



<div class="control_button"><a href="#convert-form" class="convert-link">Terms &amp; Conditions Print</a></div>

<div id="convert-form" style="display:none;">
<h2>Print Terms &amp; Conditions</h2>
<p>Fill out the form below to populate additional information in the terms and condition form. Then hit print to print a copy of the terms and conditions</p>
<form action="phpscripts/convert.tpl" method="get" target="_blank">
<input type="hidden" name="instructor_id" value="<?php echo $_SESSION['USER_ID']; ?>" />
<input type="hidden" name="student_id" value="<?php echo $_GET['id']; ?>" />
<div class="price-details left">
<fieldset>
<legend>Price Details</legend>
<div class="input-box">
<label for="prices_hour">1 Hour:</label><br />
<input type="text" name="testVariable" value="10"/>
</div>
</fieldset>
</div>
<div class="button-container">
<a id="print-button" href="phpscripts/convert-tpl.php" class="big-button button-link">Print</a>
</div>
</form>
</div>


<script type="text/javascript">
$(document).ready(function() {
$(".convert-link").fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none'
});
jQuery('#print-button').printPage({
url: jQuery('#print-button').attr('href')+'?'+jQuery('#convert-form form').serialize()
});
});
</script>






php jquery html






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 18 at 14:11









alex reesalex rees

357




357








  • 1





    Try wrapping your jQuery('#print-button').printPage({...}) with a jQuery('#print-button').on(‘click’, function(){…}), so that it doesn’t serialize() your form until you click print

    – Sean
    Jan 18 at 14:25






  • 1





    That URL gets generated straight on away on page load, which is why only the default value is used. You need to rebuild the code to build the URL when you press the button instead.

    – Magnus Eriksson
    Jan 18 at 14:25













  • I say that value of testVariable is plain static html. There is definetly some code missing, that is needed to successfully update testVariable on say page reload. And the problem it's not just building url the correct way.

    – Eugene Anisiutkin
    Jan 18 at 14:28













  • I think I'm almost there. I changed the jQuery code to the following and it is passing the variable. Now the only problem is that the #print-button needs to be pressed twice. My issue is that I don't really understand what printPage() is doing: jQuery('#print-button').on('click', function(){ jQuery('#print-button').printPage({ url: 'phpscripts/convert-tpl.php?'+jQuery('#convert-form form').serialize() }); });

    – alex rees
    Jan 18 at 14:59
















  • 1





    Try wrapping your jQuery('#print-button').printPage({...}) with a jQuery('#print-button').on(‘click’, function(){…}), so that it doesn’t serialize() your form until you click print

    – Sean
    Jan 18 at 14:25






  • 1





    That URL gets generated straight on away on page load, which is why only the default value is used. You need to rebuild the code to build the URL when you press the button instead.

    – Magnus Eriksson
    Jan 18 at 14:25













  • I say that value of testVariable is plain static html. There is definetly some code missing, that is needed to successfully update testVariable on say page reload. And the problem it's not just building url the correct way.

    – Eugene Anisiutkin
    Jan 18 at 14:28













  • I think I'm almost there. I changed the jQuery code to the following and it is passing the variable. Now the only problem is that the #print-button needs to be pressed twice. My issue is that I don't really understand what printPage() is doing: jQuery('#print-button').on('click', function(){ jQuery('#print-button').printPage({ url: 'phpscripts/convert-tpl.php?'+jQuery('#convert-form form').serialize() }); });

    – alex rees
    Jan 18 at 14:59










1




1





Try wrapping your jQuery('#print-button').printPage({...}) with a jQuery('#print-button').on(‘click’, function(){…}), so that it doesn’t serialize() your form until you click print

– Sean
Jan 18 at 14:25





Try wrapping your jQuery('#print-button').printPage({...}) with a jQuery('#print-button').on(‘click’, function(){…}), so that it doesn’t serialize() your form until you click print

– Sean
Jan 18 at 14:25




1




1





That URL gets generated straight on away on page load, which is why only the default value is used. You need to rebuild the code to build the URL when you press the button instead.

– Magnus Eriksson
Jan 18 at 14:25







That URL gets generated straight on away on page load, which is why only the default value is used. You need to rebuild the code to build the URL when you press the button instead.

– Magnus Eriksson
Jan 18 at 14:25















I say that value of testVariable is plain static html. There is definetly some code missing, that is needed to successfully update testVariable on say page reload. And the problem it's not just building url the correct way.

– Eugene Anisiutkin
Jan 18 at 14:28







I say that value of testVariable is plain static html. There is definetly some code missing, that is needed to successfully update testVariable on say page reload. And the problem it's not just building url the correct way.

– Eugene Anisiutkin
Jan 18 at 14:28















I think I'm almost there. I changed the jQuery code to the following and it is passing the variable. Now the only problem is that the #print-button needs to be pressed twice. My issue is that I don't really understand what printPage() is doing: jQuery('#print-button').on('click', function(){ jQuery('#print-button').printPage({ url: 'phpscripts/convert-tpl.php?'+jQuery('#convert-form form').serialize() }); });

– alex rees
Jan 18 at 14:59







I think I'm almost there. I changed the jQuery code to the following and it is passing the variable. Now the only problem is that the #print-button needs to be pressed twice. My issue is that I don't really understand what printPage() is doing: jQuery('#print-button').on('click', function(){ jQuery('#print-button').printPage({ url: 'phpscripts/convert-tpl.php?'+jQuery('#convert-form form').serialize() }); });

– alex rees
Jan 18 at 14:59














1 Answer
1






active

oldest

votes


















0














Just putting @Sean code in action:



$(document).ready(function () {
$(".convert-link").fancybox({
maxWidth: 800,
maxHeight: 600,
fitToView: false,
width: '70%',
height: '70%',
autoSize: false,
closeClick: false,
openEffect: 'none',
closeEffect: 'none'
});
// use on function
$('#print-button').on("click", function (e) {
$(this).printPage({
url: jQuery('#print-button').attr('href') + '?' + jQuery('#convert-form form').serialize()
});
});





share|improve this answer
























  • I tried this (see my comment above). The values are now passed, but for some reason with this code the #print-button needs to be pressed twice. Any ideas greatly appreciated.

    – alex rees
    Jan 18 at 17:17











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54255724%2fform-passing-variables-but-not-their-entered-values%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Just putting @Sean code in action:



$(document).ready(function () {
$(".convert-link").fancybox({
maxWidth: 800,
maxHeight: 600,
fitToView: false,
width: '70%',
height: '70%',
autoSize: false,
closeClick: false,
openEffect: 'none',
closeEffect: 'none'
});
// use on function
$('#print-button').on("click", function (e) {
$(this).printPage({
url: jQuery('#print-button').attr('href') + '?' + jQuery('#convert-form form').serialize()
});
});





share|improve this answer
























  • I tried this (see my comment above). The values are now passed, but for some reason with this code the #print-button needs to be pressed twice. Any ideas greatly appreciated.

    – alex rees
    Jan 18 at 17:17
















0














Just putting @Sean code in action:



$(document).ready(function () {
$(".convert-link").fancybox({
maxWidth: 800,
maxHeight: 600,
fitToView: false,
width: '70%',
height: '70%',
autoSize: false,
closeClick: false,
openEffect: 'none',
closeEffect: 'none'
});
// use on function
$('#print-button').on("click", function (e) {
$(this).printPage({
url: jQuery('#print-button').attr('href') + '?' + jQuery('#convert-form form').serialize()
});
});





share|improve this answer
























  • I tried this (see my comment above). The values are now passed, but for some reason with this code the #print-button needs to be pressed twice. Any ideas greatly appreciated.

    – alex rees
    Jan 18 at 17:17














0












0








0







Just putting @Sean code in action:



$(document).ready(function () {
$(".convert-link").fancybox({
maxWidth: 800,
maxHeight: 600,
fitToView: false,
width: '70%',
height: '70%',
autoSize: false,
closeClick: false,
openEffect: 'none',
closeEffect: 'none'
});
// use on function
$('#print-button').on("click", function (e) {
$(this).printPage({
url: jQuery('#print-button').attr('href') + '?' + jQuery('#convert-form form').serialize()
});
});





share|improve this answer













Just putting @Sean code in action:



$(document).ready(function () {
$(".convert-link").fancybox({
maxWidth: 800,
maxHeight: 600,
fitToView: false,
width: '70%',
height: '70%',
autoSize: false,
closeClick: false,
openEffect: 'none',
closeEffect: 'none'
});
// use on function
$('#print-button').on("click", function (e) {
$(this).printPage({
url: jQuery('#print-button').attr('href') + '?' + jQuery('#convert-form form').serialize()
});
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 18 at 15:39









jagdish.narkarjagdish.narkar

1997




1997













  • I tried this (see my comment above). The values are now passed, but for some reason with this code the #print-button needs to be pressed twice. Any ideas greatly appreciated.

    – alex rees
    Jan 18 at 17:17



















  • I tried this (see my comment above). The values are now passed, but for some reason with this code the #print-button needs to be pressed twice. Any ideas greatly appreciated.

    – alex rees
    Jan 18 at 17:17

















I tried this (see my comment above). The values are now passed, but for some reason with this code the #print-button needs to be pressed twice. Any ideas greatly appreciated.

– alex rees
Jan 18 at 17:17





I tried this (see my comment above). The values are now passed, but for some reason with this code the #print-button needs to be pressed twice. Any ideas greatly appreciated.

– alex rees
Jan 18 at 17:17


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54255724%2fform-passing-variables-but-not-their-entered-values%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre