message box with javascript echoed with php

Hi, I have a message box being echoed with php that if a user doesn’t upload a file this pops up and ask them if they are sure they want to submit without uploading files. However the problem that stands is the form still submits even if they click yes. If yes is clicked I just want it to go back to the form so they can choose to upload it again. I want it to exit out of the php script and not submit anything… this is what I have so far…

[php]if( $_FILES[‘ppm’][‘type’] == “”)
{
echo "

				var answer = confirm('Are you sure you do not want to upload any PPM or OM materials? This document could help the RSIC staff better process your request');
				if(answer)
				 {
					window.location('url...');
					<?php exit(); ?>
				 }
			</script>
		";
	}

[/php]
This creates a problem however the script below this code still executes and stores the information inside the database and I can’t have that…

You can’t put PHP code into JavaScript then have it executed - PHP is executed server-side whereas JavaScript is client-side. To fix this you would have to get the users’ input from the JavaScript then process the upload. One way would be to show the prompt before the form is submitted, then edit a hidden input field which you could then check with PHP.

Sponsor our Newsletter | Privacy Policy | Terms of Service