Solved

Using JQuery Dialog with php code

Posted on 2010-11-16
2
576 Views
Last Modified: 2012-05-10
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.

Thanks

Code attached below

<?php

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()) {

		

		   

		

		$this->Upload->create();

		

			$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']

				)

			);

		

		

		

		 

			

		

	

		

		//*****************************************************************

		// LETS START WITH THE VALIDATION

		//*****************************************************************

		

		

		

		

		

		//**********************************************************

		//	CHECK IF THE USER HAS ALREADY UPLOADED ANOTHER ENTRY

		//**********************************************************

		/*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 (

		

									  "application/pdf",

									  "application/msword",

									  "text/plain",

									  "text/rtf",

									  "image/gif",

									  "image/jpeg",

									  "application/x-zip-compressed", 

									  "image/jpg", 

									  "image/pjpeg",

									  "image/tiff",

									  "image/bmp",

									  "image/psd"

									  

									 );

		

		

		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

0
Comment
Question by:error77
2 Comments
 
LVL 16

Accepted Solution

by:
jmatix earned 500 total points
ID: 34151617
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>

<SCRIPT>

	$(function() {

		$( "#dialog" ).dialog();

	});

</SCRIPT>

Open in new window

0
 

Author Closing Comment

by:error77
ID: 34153424
Perfect Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now