Remember me

forms suggestions

1 year 4 months ago #1

  • BiLe's Avatar
  • BiLe
  • Posts: 324
Hello,

I would like to make the following suggestions for forms...

1. New field type for multi value input, similar to the tag field with zero app. Enter one value with input field, hit enter and the value shows below input field with delete option. User could write another value into input field,, hit enter and 2 values are shown below.

2. Default value SQL with or without joomla table prefix

3. Live check, if a specific value already exist. If true, mark field with e.g. red background or else.

4. Possibility to link php file for custom PHP after submit and be able to use field short codes with such file. This would be nice in case develper uses an editor such as UltraEdit and needs to change or search something in multiple files.

5. Link fields to necessary fields for user registration in order to create a custom register form with email or admin activation.

6. Add actual database value with dropdown options.

7. Custom validation message per field.

8. HTML Editor for Text Area

9. Dynamic upload path with field upload file e.g. /myFolder/[user_id]/ and option to delete not used files

Just some thoughts :)

1 year 4 months ago #2

  • BiLe's Avatar
  • BiLe
  • Posts: 324
10. Add field_id with file upload. I was able to find the id with the help of the calculation field ;)

1 year 4 months ago #3

  • Artem's Avatar
  • Artem
  • Posts: 11342
Wow... Okay, thank you for your suggestions. We'll take into account

Regards,
Artem, Balbooa.com

1 year 4 months ago #4

  • BiLe's Avatar
  • BiLe
  • Posts: 324
Hello,

below a function that will rename file uploads (to random 11 char) and move them to another folder.

In case there is only 1 file, the function will return string:
images/20ad7ad2745.png

In case there are multiple files, the function will return json:
["images\/91ad43a78ee.png","images\/33da72bd107.png"]

I have postet this earlier, but had to rework some lines.

Have fun :)
function formUploadRenameAndMove($field_upload, $dirname = '/images') {
	
	/*
	*
	* the return with upload of one file will be
	* images/20ad7ad2745.png
	*
	* the return with upload of multiple files will be
	* ["images\/91ad43a78ee.png","images\/33da72bd107.png"]
	*
	*/
		
	// no new filenames yet	
	$filename_new_array = array();

	// get filenames in $field_upload string by href
	$regex = '/https?\:\/\/[^\",]+/i';
	preg_match_all($regex, $field_upload, $matches);
	// create array of filenames
	$pathinfo_array = $matches[0];
	
	if (is_array($pathinfo_array)) {
		
		// count filenames
		$pathinfo_array_cnt = count($pathinfo_array);
					
		// rename and move filenames
		for ($i = 0;  $i < $pathinfo_array_cnt; $i++) {
				
			// path info
			$path_info = $pathinfo_array[$i];
			$path_basename = pathinfo($path_info, PATHINFO_BASENAME); // e.g. => test.png
			$path_filename = pathinfo($path_info, PATHINFO_FILENAME); // e.g. => test
			$path_extension = pathinfo($path_info, PATHINFO_EXTENSION); // e.g. => png
			$path_dirname_absolute = pathinfo($path_info, PATHINFO_DIRNAME); // e.g. => http://domain.com/images/folder
			$path_dirname_relative = preg_replace('#^.+://[^/]+#', '', $path_dirname_absolute); // e.g. => /images/folder
	 
			// random string
			$length = 11;
			
			if (function_exists("random_bytes")) {
				$bytes = random_bytes(ceil($length / 2));
			} elseif (function_exists("openssl_random_pseudo_bytes")) {
				$bytes = openssl_random_pseudo_bytes(ceil($length / 2));
			} else {
				echo "ERROR: no cryptographically secure random function available.";
				die();
			}

			$random_string = substr(bin2hex($bytes), 0, $length);		

			// prepare rename and move
			$filepath_old = '.' . $path_dirname_relative . '/' . $path_basename;
			$filepath_new = '.' . $dirname . '/' . $random_string . '.' . $path_extension;
			
			if (!file_exists('.' . $dirname)) {
				// create directory
				mkdir('.' . $dirname, 750);
			}
			
			if (file_exists($filepath_old)) {
				// rename and move
				rename($filepath_old, $filepath_new);
				// add file to $filename_new_array
				$filename_new = substr($dirname, 1) . '/' . $random_string . '.' . $path_extension;
				$filename_new_array[] = $filename_new;
			}
									
		}
		
	}
	
	if ($pathinfo_array_cnt > 1) {
		// multiple filenames in array
		$data = json_encode($filename_new_array);
	} elseif ($pathinfo_array_cnt == 1) {
		// one filename in array
		$data = $filename_new_array[0];
	} else {
		// no filenames in array
		$data = '';				
	}						
	
	return $data;
}

// [Field ID=10] is the upload field with forms
$data = formUploadRenameAndMove('[Field ID=10]', '/images');
Powered by Kunena Forum