Using JQuery Dialog with php code

Hi all,

I am trying to get some dialogs in my project to replace the echo's.

Can someone please help me as I cannot get it to work.

Please see code below attached.

What I need to do it to replace the echo warning messages I have in the function with popup dialogs or alert dialogs.

for example ... code below has: echo 'This file is too big'; ... I was a dialog instead.


Code attached below

class UploadsController extends AppController {
	var $name = 'Uploads';
	var $useTable = 'competitions_entry';
	var $components = array('RequestHandler','FileUpload','Session');  
	var $helpers = array('Html', 'Form', 'Javascript','Session', 'Ajax');
	var $uses = array('User','Competition','Upload', 'Vote');
	function index($id = null) {

		//$this->set('uploads', $this->Upload->find('all')); 
		$temp_id = $this->sodium_user['User']['id'];
		$theuploads = $this->Upload->query("SELECT * FROM entries where user_id <> $temp_id");
		$this->set('uploads', $theuploads);
		if($this->RequestHandler->isPost()) {
			$component = new FileUploadComponent();
			$component->upload(array('name'=>'blablabla', 'tmp_name'=>'tmp_blabla'));
			$FullUrl = $component->getFullpath();
			$currentUserId = $this->sodium_user['User']['id'];
			$test = $component->getFolder();
			$ddd = $component->getDestination();
			//Get the path to save;
			$data = array('Upload' => array(
					'competition_id' => $this->data['Upload']['comp_id'],
					'user_id' => $currentUserId,// <- Need to get this via url
			 		'directory_name'=> 'img/uploads/',
					'name' => $test.'-'.$this->data['Upload'][0]['file']['name'],
					'size' => $this->data['Upload'][0]['file']['size'], 
					'type' => $this->data['Upload'][0]['file']['type']
		/*if ($theuploads = 'Array') { //temp
			echo 'You have already voted for the competition';
		} else {*/
		//  Check the File size
		$updat = $this->data['Upload'][0]['file']['size'];
		$file_max_size = 999999;
		if ($updat > $file_max_size) { //size in bytes
			echo '<br />';
			echo 'This file is too big';
		} else {
		//If filetype is now allowed or empty give an error
		$updat2 = $this->data['Upload'][0]['file']['size'];
		$file_empty_size = 0;
		if ($updat2 == $file_empty_size) { //size in bytes
			echo '<br />';
			echo 'Upload or file cannot be empty';
		} else {
		//	Check if filetype is allowed
		$accepted_file_types = array (
		if (!in_array(strtolower($this->data['Upload'][0]['file']['type']), $accepted_file_types)) {
			echo '<br />';
			echo 'File type not allowed!';


		if($this->Upload->save($data, array('validate'=>false))) { // not validate now
		    echo 'Upload has been Saved!';	
			if(!$this->FileUpload->upload($this->data['Upload'][0]['file'])) {
			$this->Upload->delete($this->Upload->id); // remove the DB entry because there were upload errors
			$this->redirect('/'); //Redirect after saving


Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Justin MathewsCommented:
You can put the message(s) in a <div> with ID, say, dialog as:

        echo '<div id="dialog">This file is too big</div>';

Then in your <html><head> you can include the lines below. Make sure that the css and js files point to the appropriate locations.

<link type="text/css" href="../css/jquery-ui-1.8.6.custom.css" rel="stylesheet" />      
<script src="../JS/jquery.js"></script>
<script src="../JS/jquery-ui-1.8.5.custom.min.js"></script>
	$(function() {
		$( "#dialog" ).dialog();

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
error77Author Commented:
Perfect Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.