Jump to content

[SOLVED] read only form fields that transfer...?


ag3nt42

Recommended Posts

hello again all,

 

I am in the need for a text input field that displays an unchangeable value.. that will post..

Basically I'm using it to delete entries from a database..

 

You first submit an entry then upon refreshing you see the entry listed below .. I want to be able to submit this entry again to delete it. But I don't want the user to be able to change the text inputs value. other wise it won't work. any ideas on that??

 

I'll show some code i'm using so you can better understand.

 

Edit.php:

<table>
<tr>
	<td colspan='2'><h1>Client Types</h1></td>
</tr>
<tr>
	<td colspan='2'>
		<fieldset><legend>Client Types</legend>
			<form action='../Ca_info/Cct_info.php' method='post'>
				<table>
					<tr>
						<td style='text-align:right;'><label>Type: </label></td>
						<td style='text-align:left;'><input type='text' value='' name='Ctype' /></td>
					</tr>
					<tr>
						<td> </td>
					</tr>
					<tr>
						<td style='text-align:right;'><input type='reset' value='Reset' /></td>
						<td style='text-align:left;'><input type='submit' value='Submit' /></td>
					</tr>
				</table>
			</form>
		</fieldset>
	</td>
</tr>
<tr>
	<td colspan='2'><h2>Available Types</h2></td>
</tr>
");

////////////////////////
//* SNATCH AVAILABLE *//
////////////////////////

//* STOP THE BITCHING *//
$Z=array('','','','','');

$database=$tblpre."ClientType";
$AvailableSQL="SELECT Type FROM [".$database."]";
$result=mssql_query($AvailableSQL)or die(mssql_error());
$count=mssql_num_rows(mssql_query($AvailableSQL));
$y=0;
while($row=mssql_fetch_row($result))
{
$Z=$row[0];
$y++;
echo("
<tr>
	<td width='50%' style='text-align:right;'>
		<form action='../Ca_info/Cct_info.php' method='post'>
			<input type='text' value='".$Z."' name='Type".$y."' />

	</td>
	<td width='50%' style='text-align:left;'>

			<input type='submit' value='Delete' />
		</form>
	</td>
</tr>
<tr>
	<td colspan='2'> </td>
</tr>
");
}

//* IF NONE ARE AVAILABLE *//
if($count<=0)
{
echo("<tr>".PHP_EOL."<td>No Currently Available Types</td>".PHP_EOL."</tr>".PHP_EOL);
}
else
{
echo("");
}


echo("</table>".PHP_EOL."</body>".PHP_EOL."</html>");
?>

 

process.php:

////////////////////////////////
//****************************//
//* Harvest Form Information *//
//****************************//
////////////////////////////////
//ADD
if(!(isset($_POST['Ctype']))){$Ctype='None';}else{$Ctype=$_POST['Ctype'];}


//DELETE
//* STOP THE BITCHING *//
$Type= array('','','','','');
$Z=array('','','','','');

//* CHECK HOW MANY *//
$database=$tblpre."ClientType";
$AvailableSQL="SELECT * FROM [".$database."]";
$result=mssql_query($AvailableSQL)or die(mssql_error());
$y=0;
$count=mssql_num_rows(mssql_query($AvailableSQL));
while($row=mssql_fetch_row($result))
{
$Z[$y]=$row[0];
$y++;
}


////////////////////////////
//************************//
//* Setup SQL Variables  *//
//************************//
////////////////////////////
//The Table+Prefix
$datatable=$tblpre."ClientType";

//COLLECT DELETE INPUT
for($x=0;$x<=$count;$x++)
{
if(!(isset($_POST['Type'.$x]))){$Delete='No';$Type[$x]='';}else{$Delete='Yes';$Type[$x]=$_POST['Type'.$x];}

//SQL VARIABLE MUST BE SET HERE FOR X TO BE CORRECT
$TypeDelete="DELETE FROM [".$datatable."] WHERE Type='".$Type[$x]."'";
}



$TypeInsert="INSERT INTO [".$datatable."] VALUES ('".$Ctype."');";


////////////////////////////
//************************//
//* Start SQL Injections *//
//************************//
////////////////////////////
$Success=0;
$Fail=0;
// IF ADDING
if($Delete=='No')
{
if(mssql_query($TypeInsert))
{
	echo("<font color='green'>".$Ctype."Type Added Successfully!</font><br />");
	$Success++;
}

else
{
	echo("<font color='red'>".$Ctype."FAILED</font>".mssql_error());
	$Fail++;
}
}
//IF DELETING
elseif($Delete=='Yes')
{
if(mssql_query($TypeDelete))
{
	echo("<font color='green'>Type Deleted Successfully!</font><br />");
	$Success++;
}
else
{
	echo("<font color='red'>FAILED</font>".mssql_error());
	$Fail++;
}
}

Link to comment
Share on other sites

ok not solved.. sry...

 

thought that was going to work but It screws up my logic because now the variable is ALWAYS set..

so since it is set it always deletes. Even when submitting

 

p.s. I wana know who's bright idea it was to make READONLY inputs not post..(dumbarse)... isn't that what "disabled" should take care of

Link to comment
Share on other sites

well the forms are all on the same page.. but I just don't want them to be able to edit the field input.. If I make them anything other then a submitable value.. then they are constantly set which makes it impossible for me to reference what they are doing. If the variable is always set then how do i say they are deleting rather then submitting?

 

on the other hand I spose i could just make an invisible input and echo out as text as you said.. that way I have both. and its not always set... That just may work

Link to comment
Share on other sites

well the forms are all on the same page.. but I just don't want them to be able to edit the field input.. If I make them anything other then a submitable value.. then they are constantly set which makes it impossible for me to reference what they are doing. If the variable is always set then how do i say they are deleting rather then submitting?

 

on the other hand I spose i could just make an invisible input and echo out as text as you said.. that way I have both. and its not always set... That just may work

 

maybe I'm not understanding right, but how about instead of making a disabled field, you just echo out the value and make a hidden field?

 

thats wat i was thinking/\

 

thanks tho.

 

That definatley did the trick

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.