Jump to content

PHP & JavaScript Question/Problem.


N1CK3RS0N

Recommended Posts

Hello,

 

I found a nice script that worked great for one thing, and was wondering if there's any way to use it for another thing I need.

 

The script is simple. If a check box is checked, then the submit button for the form becomes enabled. By default the checkbox is unchecked. I require them to check to box to agree to the licensing for the software during the installation, and once its checked the submit button becomes clickable. Works great.

 

I have another need sort of like that. The script needs to check file permissions and folder permissions as well as some server settings to make sure the software will function properly. I wrote a PHP function that will check the permissions, and if it passes it will display "PASS" if it fails it will display "FAIL". I want the submit button to only be clickable if every field has "PASS".

 

I figured I could probably edit the script to work with hidden inputs or something. But I have almost no knowledge of JavaScript.

 

Was wondering if someone out there had any ideas of how I could get this to work.

 

<script language="JavaScript" type="text/JavaScript">
function required_field() {
	if (document.getElementById('gpl').checked) {
		document.getElementById('submit').disabled = false;
	} else {
		document.getElementById('submit').disabled = true;
	}
}
</script>

 

Thanks!

Link to comment
Share on other sites

Hi,

 

Why you have to do that in javascript.you can check if every field has passed in php itself.if every field has passed then send the submit button from the script...else dont.something like

 

$passed=true;

foreach($fields as $v)

{

if($v['passed']!=true)  $passed=false;

}

 

if($passed)

{

echo "<input type=submit' >";

}

 

 

 

 

 

Link to comment
Share on other sites

Hi,

 

Why you have to do that in javascript.you can check if every field has passed in php itself.if every field has passed then send the submit button from the script...else dont.something like

 

$passed=true;

foreach($fields as $v)

{

if($v['passed']!=true)  $passed=false;

}

 

if($passed)

{

echo "<input type=submit' >";

}

 

 

Well heres how the file works right now

 

<?php

$templatefile = "setup";

function check_perms($file, $perm) {
if (substr(decoct(fileperms("$file")),2) == $perm) {
	return "<div class=\"container\" style=\"color: #008000; font-weight:bold;\">Pass</div>";
} else {
	return "<div class=\"container\" style=\"color: #D00000; font-weight:bold;\">Fail</div>";
}
}

$backups = check_perms('../backups/', '777');
$downloads_uploads = check_perms('../downloads/uploads/', '777');
$images_uploads = check_perms('../images/uploads/', '777');
$images_banners = check_perms('../images/banners/', '777');
$include_config = check_perms('../includes/config.php', '666');
$languages = check_perms('../languages/', '777');
$modules = check_perms('../modules/', '777');
$templates = check_perms('../templates/', '777');

require 'smarty.php';

$smarty->assign ('step', "step3");

$smarty->assign ('nav_01', "nav_over_01");
$smarty->assign ('nav_02', "nav_over_02");
$smarty->assign ('nav_03', "nav_over_03");
$smarty->assign ('nav_04', "nav_04");
$smarty->assign ('nav_05', "nav_05");
$smarty->assign ('nav_06', "nav_06");

$smarty->assign ('backups', $backups);
$smarty->assign ('downloads_uploads', $downloads_uploads);
$smarty->assign ('images_uploads', $images_uploads);
$smarty->assign ('images_banners', $images_banners);
$smarty->assign ('include_config', $include_config);
$smarty->assign ('languages', $languages);
$smarty->assign ('modules', $modules);
$smarty->assign ('templates', $templates);

require 'display.php';

?>

 

The function is to get the text to print in my template files.

Link to comment
Share on other sites

HI,

 

I think the shortest way to fix this would be to modify the function check_perm to modify a global variable ,so that if some field fails the test ,the variable is set to false.then check for that variable to see wether submit button must be shown...code will be

 

<?php
function check_perms($file, $perm,) {
   if (substr(decoct(fileperms("$file")),2) == $perm) {
      return "<div class=\"container\" style=\"color: #008000; font-weight:bold;\">Pass</div>";
   } else {
      return "<div class=\"container\" style=\"color: #D00000; font-weight:bold;\">Fail</div>";
   

    global $pass_flag; 
    $pass_flag=false; 


   }
}

$pass_flag=true;

$backups = check_perms('../backups/', '777');
$downloads_uploads = check_perms('../downloads/uploads/', '777');
$images_uploads = check_perms('../images/uploads/', '777');
$images_banners = check_perms('../images/banners/', '777');
$include_config = check_perms('../includes/config.php', '666');
$languages = check_perms('../languages/', '777');
$modules = check_perms('../modules/', '777');
$templates = check_perms('../templates/', '777');
   


require 'smarty.php';

$smarty->assign ('step', "step3");

$smarty->assign ('nav_01', "nav_over_01");
$smarty->assign ('nav_02', "nav_over_02");
$smarty->assign ('nav_03', "nav_over_03");
$smarty->assign ('nav_04', "nav_04");
$smarty->assign ('nav_05', "nav_05");
$smarty->assign ('nav_06', "nav_06");

$smarty->assign ('backups', $backups);
$smarty->assign ('downloads_uploads', $downloads_uploads);
$smarty->assign ('images_uploads', $images_uploads);
$smarty->assign ('images_banners', $images_banners);
$smarty->assign ('include_config', $include_config);
$smarty->assign ('languages', $languages);
$smarty->assign ('modules', $modules);
$smarty->assign ('templates', $templates);



$smarty->assign('show_submit_button',$pass_flag);

require 'display.php';


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.