Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/248876-creating-pdfs-using-php-and-javascript/
Share on other sites

$('#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?

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.

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.

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>";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.