Jump to content
newbiephp2020

onload function repeating

Recommended Posts

Hi guys i am a complete novice learning.

I want to automatically load a form page without using the submit button.

i can get the page to load no problems but the url keeps refreshing in the browser window ? here is the code i am using.

 

<h3>View Mileage.</h3>

		
		<form method="post" action="testmileage.php" name="mileage" id = "mileage">

		
		<input type="hidden" name="start-date" value="2020-04-06">

		
		<input type="hidden" name="end-date" value="2021-04-05">

		
		</form>


<script>window.onload = function(){
  document.mileage.submit();
};</script>

 

Share this post


Link to post
Share on other sites

I'm not following what you want to do. You say you want the page to reload without clicking the submit button. That is what it is doing which makes no sense. There must be some condition, you did not explain, that will cause a reload without the submit button.

Share this post


Link to post
Share on other sites

What is the name of the page this form is on? Is the form submitting to itself?

Share this post


Link to post
Share on other sites

here is the full page code

 

<?php

session_start();

include('../inc/config.php');

include(ROOT_PATH . 'inc/functions.php');



if (!isset($_SESSION['login'])) {

	header("Location: " . BASE_URL . "account/login.php");

	exit;

}



if (isset($_SESSION['membership_expired'])) {

	header("Location: " . BASE_URL . "account/upgradeaccount.php?expired=true");

	exit;

}



$mileage_data = yegetMileageByUserId($_SESSION['login']['id']);



include(ROOT_PATH . 'inc/header.php');

?>



<div id="wrapper">

	<?php include(ROOT_PATH . 'inc/partials/account-nav.php'); ?>



	<div id="account-info">

		<h3>View Mileage.</h3>

		
		<form method="post" action="testmileage.php" name="mileage" id = "mileage">

		
		<input type="hidden" name="start-date" value="2020-04-06">

		
		<input type="hidden" name="end-date" value="2021-04-05">

		
		</form>


<script>window.onload = function(){
  document.mileage.submit();
};</script>



		<?php if ($_POST) { ?>

		<?php $total = 0; ?>

		<?php foreach($mileage_data as $mileage) { ?>

		<?php $total += $mileage['mileage_amount']; ?>

		<?php } ?>

		<?php if (!empty($total)) { ?>

		<input type='button' id='print-page' value='Print' onclick='window.print();'>

		<div id="datatables-wrapper"  style="max-height:500px;overflow:scroll;">

				<p><?php echo htmlspecialchars($_SESSION['login']['customer_name']); ?></p>

				<p><?php echo htmlspecialchars($_SESSION['login']['company_name']); ?></p>

				<p class="total">Total Mileage From Dates Selected:<br> <b><?php echo $total; ?> Miles</b></p>

				<table class="printable-table">

				<thead>

					<tr>

						<th>Mileage date</th>

						<th>Mileage amount</th>

					</tr>

				</thead>

				<tbody>

				<?php foreach($mileage_data as $mileage) { ?>

					<tr>

						<?php $mileage_date = new DateTime($mileage['mileage_date']); ?>

						<td><?php echo $mileage_date->format('d M Y'); ?></td>

						<td><?php echo htmlspecialchars($mileage['mileage_amount']); ?></td>

					</tr>

				<?php } ?>

				</tbody>

				</table>

			<?php } ?>

		<?php } ?>

		</div>

	</div>

</div>



<?php 

include(ROOT_PATH . 'inc/footer.php');

?>

<script language=JavaScript>
<!--

//Disable right click script III- By Renigade (renigade@mediaone.net)
//For full source code, visit http://www.dynamicdrive.com

var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
// --> 
</script>

 

Share this post


Link to post
Share on other sites

What's the purpose of having a form if there's no submit button? 

Edited by Strider64

Share this post


Link to post
Share on other sites
34 minutes ago, Strider64 said:

What's the purpose of having a form if there's no submit button? 

The whole auto-submit thing doesn't make any sense.

Share this post


Link to post
Share on other sites

Perhaps the OP is confusing server side (PHP) stateless operation vs client side (javascript) operation.

Share this post


Link to post
Share on other sites

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.