garteth Posted October 11, 2011 Share Posted October 11, 2011 Hi I am wanting to create a site that will allow a user to input to and from dates and then display the results onto a page using php and mysql. Once the results are on the page they can have the option of exporting the results to PDF. I am currently using dompdf to create the PDF however it seems as though once the submit button has been pressed the PHP grabs the values entered in the fields and turns them into variables. This is fine and is obviously what I need to happen in order to display the data onto the page. The only thing is that I want JavaScript to also grab the values if the export to pdf button is clicked and redirect to another page which creates the pdf. The code below is what I am using to do this: $('#pdfbutton').click(function() { var start = $('#startdate').val(); var end = $('#enddate').val(); window.location.replace("now.php?startdate=" + start + "&enddate=" + end); }); The only thing is when you click the button it redirects with no values in the URL. Does anyone have any ideas of how to get around this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 $('#pdfbutton').click(function() { var start = $('#startdate').val(); var end = $('#enddate').val(); alert(start) alert(end) }); if this doesnt give you anything on the alert box, then there is something wrong with the start and end date values. what is start date and end date? are they input boxes or divs? Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278078 Share on other sites More sharing options...
garteth Posted October 11, 2011 Author Share Posted October 11, 2011 They are input boxes. Its just like any normal HTML form that is posting data and querying a mysql database and returning the results, however after the results are displayed I want to grab the dates that were input Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278082 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 post your now.php code. have you done what i've asked you to do? did you get any alert box with data? Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278087 Share on other sites More sharing options...
garteth Posted October 11, 2011 Author Share Posted October 11, 2011 Hi I did what you said and nothing appeared in the pop up boxes. I have taken out the pdf code and used the following for now.php in order to see if it will print the values. <?php require_once('auth.php'); ?> <?php require_once ('connect.php'); // Connect to the database. if (!empty($_GET['startdate'])) { $date = ($_GET['startdate']); } else { $date = FALSE; echo '<p><font color="red">Please enter the Course ID!</font></p>'; } if (!empty($_GET['enddate'])) { $date2 = ($_GET['enddate']); } else { $date2 = FALSE; echo '<p><font color="red">Please enter the Course ID!</font></p>'; } echo "$date"; echo "$date2"; Also I should mention that the link to the now.php is dynamic and is created once the query has run. If I click it once the query has run then the JavaScript does not do its job, but if I create the link as a static html link and then type in the two values and click the button the it works. Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278140 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 what do you mean the link to now.php is dynamic? whats the point of having seperate <?php ?> tags? <?php require_once('auth.php'); require_once ('connect.php'); // Connect to the database. if (!empty($_GET['startdate'])) { $date = $_GET['startdate']; } else { $date = "FALSE"; echo '<p><font color="red">Please enter the Course ID!</font></p>'; } if (!empty($_GET['enddate'])) { $date2 = $_GET['enddate']; } else { $date2 = "FALSE"; echo '<p><font color="red">Please enter the Course ID!</font></p>'; } echo $date; echo $date2; try that code instead. Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278209 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 post the form code. i think there is something wrong with your form code. Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278210 Share on other sites More sharing options...
garteth Posted October 11, 2011 Author Share Posted October 11, 2011 Ok I see your point on the separate tags. Below I have my form code: <form method="post" name="chooseDateForm" id="chooseDateForm" action="member-index-period.php"> <input type="hidden" name="MAX_FILE_SIZE" value="524288"> <fieldset> <legend>Test date picker form</legend> <ol> <li> <label for="startdate">Start date:</label> <input name="startdate" id="startdate" class="date-pick dp-applied"> </li> <li> <label for="enddate">End date:</label> <input name="enddate" id="enddate" class="date-pick dp-applied"> </li> <li> <input type="submit" name="Submit" id="Submit" value="Submit" /> </ol> </fieldset> <input type="hidden" name="submitted" value="TRUE" /> </form> Now here is the php code I use to display the results to the page: <?php require_once ('connect.php'); // Connect to the database. if (isset($_POST['submitted'])) { // Check if the form has been submitted. if (!empty($_POST['startdate'])) { $date = ($_POST['startdate']); } else { $date = FALSE; echo '<p><font color="red">Please enter the Course ID!</font></p>'; } if (!empty($_POST['enddate'])) { $date2 = ($_POST['enddate']); } else { $date2 = FALSE; echo '<p><font color="red">Please enter the Course ID!</font></p>'; } echo '<div id="pdfbutton" style="position: absolute; top:400px; right:200px;"> <img src="images/view_as_pdf.png"></div>'; $result = mysql_query("SELECT * FROM audit WHERE user = '" . $_SESSION['SESSUSER'] . "' AND date >= \"$date\" AND date <= \"$date2\""); echo "<table border='1'>"; echo "<tr> <th>Date</th> <th>Destination</th> <th>Reply</th> <th>Identifier</th> <th>IP Address</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . date("d-m-Y", strtotime($row["date"])) . "</td>"; echo "<td>" . $row['dest'] . "</td>"; echo "<td>" . $row['reply'] . "</td>"; echo "<td>" . $row['identifier'] . "</td>"; echo "<td>" . $row[origip'] . "</td>"; echo "<td>" . $row[text'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "</br>"; Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278213 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 this line echo "<td>" . $row['origip'] . "</td>"; you are missing a quote. should be echo "<td>" . $row[origip'] . "</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278220 Share on other sites More sharing options...
garteth Posted October 11, 2011 Author Share Posted October 11, 2011 Sorry that is actually there i just cut off what was before it. So do you think that there is anyway that I can post the form details, print them to the page and then send the input field values to another page(now.php)? Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278229 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 yes. use $_SESSION[]; Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278231 Share on other sites More sharing options...
garteth Posted October 11, 2011 Author Share Posted October 11, 2011 but I am already using sessions for my login script so how would i go about doing this? Could you give me an example of the code you would use. Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278255 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 <?php session_start(); $_SESSION['startdate'] = $_POST['startdate']; $_SESSION['enddate'] = $_POST['enddate']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/#findComment-1278257 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.