Hi

I have this login page where user enters in and goes to main page, it has a button called enter form >> which on clicks go to a form submission page .

The user enters the form and click submit, once he click submit the form is submitted and in the previous page(which is the main page) the enter form >> button is disabled.

What i have done is i took the value of the submit button from the form page and store in the database.

Then in the previous page(which is the main page), i did a if condition that if the value is submit, disable the enter form >> button...But i think i have some errors in it... it doesnt show any error, but the enter form >> button is not disabled...

Login page >> Main Page(which has the enter form > button) >> Form Page >>

I tried using some javascript also but no idea.....hmm...

My code is as

<script language="javascript">
function disable()
{
document.form1.button.disabled = true;
}
</script>

</head>

<body>
 <?php
$db = "db";
$link = mysql_connect("localhost","root","");
if (!$link)
{
die("Couldn't connect to MySQL");
}

mysql_select_db("db",$link)
or die("Couldn't open $db: ".mysql_error($link));

$query = "SELECT sbutton FROM user_report";
//$result = mysql_query($query) or die(mysql_error());
$result = mysql_query($query);
$row = mysql_fetch_array($result);
//$ic=$row->sbutton;
//$ic=$row["sbutton"];
if ($row == 'Submit') 
{
echo "<SCRIPT LANGUAGE='javascript'>disable();</SCRIPT>";
//$disabled = 'disabled = "disabled"'; 
}
?>
<form id="form1" name="form1" method="post" action="report1.php">
  <label>
<input type="submit" name="button" id="button" value="Create Form"/>
  </label>
</form>
</body>
</html>

Where have i gone wrong...

Recommended Answers

All 11 Replies

you could try creating a session $_SESSION; which could hold a boolean value.

On clicking the button, give that variable a value, and the same on each page. if it has a value, dont show the button, if it doesnt then do

you could try creating a session $_SESSION; which could hold a boolean value.

On clicking the button, give that variable a value, and the same on each page. if it has a value, dont show the button, if it doesnt then do

Hey ,
I coudnt able to understand it... and i m not that gud in using sessions... Could u pls help me with the sample codes...

Thanks...

A session is a global variable which allows information to be held until the session is ended.

An important thing to remember is that at the top of each page where a session is used you should use session_start();

<php?
session_start();
?>
//start of menu
<ul>
<li><a href="index.php"/>main</a></li>
<?php if ($_SESSION['messagesent'] !="") 
                 { echo "<li><a href="sendmessage.php"
                 }else{ exit();?>
</ul>

This will only show that list item if the session is not empty

On your form, when sent you could have some logic to say if the session == something then say "thanks for filling this in"

<php?
session_start();
?>
//start of menu
<ul>
<li><a href="index.php"/>main</a></li>
<?php if ($_SESSION !="")
{ echo "<li><a href="sendmessage.php"  HOw about this line ? IS there any error in it                }else{ exit();?>
// In this after the exit(); havent closed with }
</ul>

This will only show that list item if the session is not empty.
wat value is the session calling? $_SESSION --- In this what is message sent.

On your form, when sent you could have some logic to say if the session == something then say "thanks for filling this in"
Explain the above line? Is it in the form page..? must we use session in the form page also... then how is the session called in...?

Hi

I have this login page where user enters in and goes to main page, it has a button called enter form >> which on clicks go to a form submission page .

The user enters the form and click submit, once he click submit the form is submitted and in the previous page(which is the main page) the enter form >> button is disabled.

What i have done is i took the value of the submit button from the form page and store in the database.

Then in the previous page(which is the main page), i did a if condition that if the value is submit, disable the enter form >> button...But i think i have some errors in it... it doesnt show any error, but the enter form >> button is not disabled...

Login page >> Main Page(which has the enter form > button) >> Form Page >>

I tried using some javascript also but no idea.....hmm...

My code is as

<script language="javascript">
function disable()
{
document.form1.button.disabled = true;
}
</script>

</head>

<body>
 <?php
$db = "db";
$link = mysql_connect("localhost","root","");
if (!$link)
{
die("Couldn't connect to MySQL");
}

mysql_select_db("db",$link)
or die("Couldn't open $db: ".mysql_error($link));

$query = "SELECT sbutton FROM user_report";
//$result = mysql_query($query) or die(mysql_error());
$result = mysql_query($query);
$row = mysql_fetch_array($result);
//$ic=$row->sbutton;
//$ic=$row["sbutton"];
if ($row == 'Submit') 
{
echo "<SCRIPT LANGUAGE='javascript'>disable();</SCRIPT>";
//$disabled = 'disabled = "disabled"'; 
}
?>
<form id="form1" name="form1" method="post" action="report1.php">
  <label>
<input type="submit" name="button" id="button" value="Create Form"/>
  </label>
</form>
</body>
</html>

Where have i gone wrong...

function disable()
{
document.getElementById("button").style.display = "none";
				
	}

try like this.

A session is a global variable which allows information to be held until the session is ended.

An important thing to remember is that at the top of each page where a session is used you should use session_start();

<php?
session_start();
?>
//start of menu
<ul>
<li><a href="index.php"/>main</a></li>
<?php if ($_SESSION['messagesent'] !="") 
                 { echo "<li><a href="sendmessage.php"
                 }else{ exit();?>
</ul>

This will only show that list item if the session is not empty

On your form, when sent you could have some logic to say if the session == something then say "thanks for filling this in"

function disable()
{
document.getElementById("button").style.display = "none";
				
	}

try like this.

I tried that.. but still doesnt work..

on the script where your user inputs and clicks go, you should give the session variable a value, so if the session has a variable it wont show the button.

session_start();
//the forms has been sent
echo "Thanks, your info has been recieved";
$_SESSION['something'] = sent;

Then when you return to the menu the button will have disspaeared

<?
ob_start();
session_start();
//$ic=$row->sbutton;
//$ic=$row["sbutton"];
if ($_POST['button'] == 'Create Form')
{
$_SESSION['btn']="disable";
header("location:report1.php");
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>


</head>

<body>
<form id="form1" name="form1" method="post" action="">
<label>
<?php

if($_SESSION['btn']!="disable")
{?>
<input type="submit" name="button" id="button" value="Create Form"/>
<?
} 
else
{
echo"Thanks, your info has been recieved";
}
?>

</label>
</form>
</body>
</html>

try like this

sorry line 7 on first lot of code should say

== "")

sorry line 7 on first lot of code should say

== "")

Hi thanks for ur code... looks it might get work.. but somewhere i m going wrong....

After the user login in... he goes to this page:
test.php

<?php
session_start();
?>
//start of menu
<ul>
<li><a href="report1.php">main</a></li>
<?php if ($_SESSION['submit'] =="") 
                 { 
				 echo "<li><a href='report1.php'>FORM</a></li>";
                 }
				 else
				 { 
				 echo "None";
				 //exit();
				 }
				 ?>
</ul>

When i run the previous code, I can see the "Main" and the None...i cannot see the <li> of the "FORM"....
then when the user click on "Main" it goes to report1.php
where i have my form
report1.php

<?php
session_start();
//the forms has been sent
echo "Thanks, your info has been recieved";
$_SESSION['submit'] = "sent";
?>
<html>
<head>
<title>Untitled Normal Page</title>
<SCRIPT LANGUAGE="JavaScript">
      function confirmAction() {
        return confirm("Do you really want to submit this form?")
      }
   function checkme() {
missinginfo = "";
if (!document.form.agree.checked) {
missinginfo += "\n - You must agree to the terms";
} 
if (missinginfo != "") {
missinginfo ="---\n" +
"Required information is missing: \n" +
missinginfo + "\n---" +
"\nPlease complete and resubmit.";
alert(missinginfo);
return false;
}
else { 
return true;
}
}


</SCRIPT>
</head>

<body>
<p><strong>REPORT 1<br />
</strong>*********</p>
<form method="post" action="reportform_process.php" onSubmit="return confirmAction()">
  <strong>
  <label>  </label>
  </strong>
  <label>Address :
  <input type="text" name="add" id="add" />
  </label>
  <p>Name : 
    <input type="text" name="top_name" id="top_name" />
  </p>
  <p>Designation : 
    <input type="text" name="top_desig" id="top_desig" />
  </p>
  <p>Email :
    <input type="text" name="top_email" id="top_email" />
</p>
  <p>Telephone : 
    <input type="text" name="top_telephone" id="top_telephone" />
  </p>
  <p>Total Grant : 
    <input type="text" name="top_grant" id="top_grant" />
  </p>
  <p>Country : 
    <label>
    <input name="ucountry" type="radio" id="radio" value="Singapore" checked="checked" />
    </label>
    Singapore 
    <label>
    <input type="radio" name="ucountry" id="radio2" value="Israel" />
    </label> 
    Israel</p>
  <p>
    <label></label>
  </p>
  <p>
    <label>
    <input type=submit name="button" value="Submit">
    <!--<input type="submit" name="button" id="button" value="Submit" />-->
    </label>
</p>
</form>
<p>&nbsp;</p>
</body>
</html>

I am not sure if i have added the code right...
Can u tell me where i have gone wrong...i m lost in it...:(

Hi whiteyoh,

ur code helps..thanks a lot..but there is somewhere some mistake...
which i coudnt able to find it out..
the form button appears sometimes, sometimes get disappeared...
i dont know why ?
Below are my codes:
userlogin_sucess.php

<?php
session_start();
?>
<ul>
<li><a href="report1.php">main</a></li>
<p>
  <?php if ($_SESSION['submit'] =="") 
                 { 
				 echo "<li><a href='report1.php'>FORM</a></li>";
                 }
				 else if($_SESSION['submit'] =="sent") 
				 { 
				 echo "None";
				 //exit();
				 }
				 ?>
</p>
</ul>

This on click of the FORM link, it goes to next page..where i enter the form details and submit... On submit of the form it process the reportform_process.php in the form action of the report page..

reportform_process.php

<?php
session_start();
//the forms has been sent
echo "Thanks, your info has been recieved";
//$_SESSION['submit'] = "sent";
?>
<style type="text/css">
<!--
.style1 {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>
<table width="960" border="0">
  <tr>
    <td width="391">Home</td>
    <td width="276">Submitted forms</td>
    <td width="279"><p><a href="logout.php">Logout</a></p></td>
  </tr>
</table>
<p><span class="style1">your data has been successfully submitted.</span>
  <?php
$db = "db";
$link = mysql_connect("localhost","root","");
if (!$link)
{
die("Couldn't connect to MySQL");
}

mysql_select_db("db",$link)
or die("Couldn't open $db: ".mysql_error($link));
$raddress = $_POST["add"];
$rname = $_POST["top_name"];
$rdesignation = $_POST["top_desig"];
$remail = $_POST["top_email"];
$rtelephone = $_POST["top_telephone"];
$rtotal_grant= $_POST["top_grant"];
$rcountry = $_POST["ucountry"];
$submit = $_POST["button"];
?>
  
  
  <?php
  $query = "INSERT INTO user_report(address, tname, desig, email,telephone, total_grant, country ,sbutton)"."VALUES('$raddress', '$rname' , '$rdesignation' , '$remail' , '$rtelephone' , '$rtotal_grant' , '$rcountry' , '$submit')";
 $_SESSION['submit'] = "sent";
  //$_SESSION['submit'] = $submit;
				mysql_query($query,$link)
					or die("Couldn't add data to add to \"Report Form\" table: 
".mysql_error($link));

				mysql_close($link);
				?>
  <?php

  $date = date('l dS \of F Y');
  echo "<br></br>";
  $date1 = date("d.m.y");

  echo "$date";
  echo "<br></br>";
  echo "You have submitted the Report on $date1";

?>
</p>
<p>Address : <?php print "$raddress" ?></p>
<p>Name :  <?php print "$rname" ?></p>
<p>Designation : <?php print "$rdesignation" ?></p>
<p>Email : <?php print "$remail"?></p>
<p>Telephone :  <?php print "$rtelephone"?></p>
<p>Total Grant :  <?php print "$rtotal_grant"?></p>
<p>Country : <?php print "$rcountry"?></p>

(The main concept is, i have 2 users..
What i want to have is like, when the user1 enter in he see the userlogin_sucess.php page. on click of create FORM>> it goes to the form page..where he enters all the details and click submit >>
Once the data are submitted, the create FORM>> button has to be deactivated... When User1 submits the form details, it goes to User2 for confirming.. After User2 login with his a/c he confirms the form data that was submitted by the User1 then the create FORM >> button gets activated...until then the User1 wont be able to create another form.. )....
The code works... but not correctly...
Could u help me where i have gone wrong...in the prev code that i have submitted...:confused:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.