Closed Thread Icon

Topic awaiting preservation: if statement to check <textarea></textarea> for text (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26198" title="Pages that link to Topic awaiting preservation: if statement to check &amp;lt;textarea&amp;gt;&amp;lt;/textarea&amp;gt; for text (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: if statement to check &lt;textarea&gt;&lt;/textarea&gt; for text <span class="small">(Page 1 of 1)</span>\

 
Seymour
Bipolar (III) Inmate

From: K-town, FL, USA
Insane since: Jun 2002

posted posted 07-08-2005 05:40

I know that the if statement will return true for $_POST[subject_address] because I tested it separately. The problem is that I am ubable to code this so that it can check to see if the text area contains any data.


code:
<tr>	
			<td><strong>Legal Description:</strong></td>
			<td><textarea name=\"legal_description\" cols=30 rows=5 wrap=virtual> $_POST[legal_description]
			</textarea></td>
		</tr>



code:
if($_POST[legal_description]=="" && $_POST[subject_address]=="")
		{
		$legal_err="<font color=red>Must provide legal description or subject address</font><br />";
		$send="no";
		}




if the you need the rest of the code for the page it can be found in an eariler post about another problem
http://www.ozoneasylum.com/26126

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-08-2005 07:07

For one, $_POST[legal_description] should have quotes: $_POST['legal_description']

Second, I would use emtpy() rather than comparing to ""

third, and what would appear to be your main problem -

you are checking to see if the legal_description AND the subject_address are empty.

you need to either check each individually, or use OR rather than AND ( || rather than &&)



(Edited by DL-44 on 07-08-2005 07:08)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-08-2005 16:12

isset() is also your friend.

Your code is pretty complex as well it will help to bring as much out as you can. This will allow you to do validation and other functions on your variables much easier than if you have it nested in the logic. When you need to change your code it will be much easier, and if you get into the practice of doing this it will save you a whole lot of time. When your small webapp gets huge it really makes a difference.

I would also make you send area a boolean for use during your logic operations. Using it as a yes no during your logic can be confusing. I would also have it initially set to false, that way malformed data will find it harder to get throught to your processing engine.

Finally do your styling at the end in one block, it will make your life easier again if you need to change the styling you are not hunting through your application to find out where you have styled things, and also font is depricated do your font styling with CSS.

code:
$legalDescription = $_POST['legal_description'];
$subjectAddress = $_POST['subject_address'];

/** This boolean stuff should work, if not you will have to do it in a separate function **/
$legalDescriptionSet = isset($legalDescription) && !empty($legalDescription);
$subjectAddressSet = isset($subjectAddress) && !empty($legalDescription);

$send = false;

/** The logic which is now really simple and easy to read **/
if( $legalDescriptionSet && $subjectAddressSet){
  /** You have both values you can do your processing on it **/
  $send = true;
} else if ($legalDescriptionSet){
  $error = "You must provide a valid legal description.";
} else if ($subjectAddressSet) {
  $error = "You must provide a valid subject address.";
} else {
  $error = "You must provide a valied legal description and subject address.";
}

/** Styling of the error (only if you have one)**/
if(isset($error){
  $error = "<p class="errorMessage">" . $error . "</p>";
}



Dan @ Code Town

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-08-2005 18:28

sorry if i am misreading, but shouldn't this -

code:
} else if ($legalDescriptionSet){
  $error = "You must provide a valid legal description.";
} else if ($subjectAddressSet) {
  $error = "You must provide a valid subject address.";



be

code:
} else if (!$legalDescriptionSet){
  $error = "You must provide a valid legal description.";
} else if (!$subjectAddressSet) {
  $error = "You must provide a valid subject address.";


?

(Edited by DL-44 on 07-08-2005 18:28)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-08-2005 20:33

That works, I what I was aiming for was just a reversal of where the messages go.

code:
} else if ($legalDescriptionSet){
  $error = "You must provide a valid subject address.";
} else if ($subjectAddressSet) {
  $error = "You must provide a valid legal description.";



Sorry for the logic error.

Dan @ Code Town

Seymour
Bipolar (III) Inmate

From: K-town, FL, USA
Insane since: Jun 2002

posted posted 07-14-2005 19:46

Alright I have gone back and reformatted all of the code to make it easier for me to make changes but I am still having problems checking the textarea of my legal description for input. I can get all of the input fields to check but for some reason I cannot do this with the textarea. Im not sure if it is possible to make a check like this on a textarea or what but I have googled for an answer and returned nothing. I have posted the new code below

Here is the site if you need to see the functionality of the code
www.seymoursworld.com/smithparke/email_order.php

code:
<form method="post" action="email_order.php">
	Please fill out the required fields below  then click the submit button.<br /><br />

	<table>
		<tr>
			<td><strong>Name of Borrower:</strong></td>
			<td><input type="text" name="borrower_name" value="" size=30></td>
		
		</tr>
	
		<tr>
			<td><strong>Name of Client (Lender):</strong></td>

			<td><input type="text" name="client_name" value="" size=30></td>
		</tr>
	
		<tr>
			<td><strong>Attention:</strong></td>
			<td><input type="text" name="attention" value="" size=30></td>
		</tr>
	
		<tr>
			<td><strong>Subject Address:</strong></td>

			<td><input type="text" name="subject_address" value="" size=30></td>
		</tr>
	
		<tr>	
			<td><strong>Legal Description:</strong></td>
			<td><textarea name="legal_description" cols=30 rows=5 wrap=virtual>
			</textarea></td>
		</tr>

		<tr>
			<td><strong>Access to Property:</strong></td>

			<td><input type="text" name="access_property" value="" size=30></td>
		</tr>
	
		<tr>
			<td><strong>Owner of Record:</strong></td>
			<td><input type="text" name="owner_record" value="" size=30></td>
		</tr>
</table>
<input type="hidden" name="op" value="ds">

<p><input type="submit" name="submit" value="submit"></p>

</form>




code:
<?php


//Error_reporting(E_ALL);

$borrower_name = $_POST['borrower_name'];
$client_name = $_POST['client_name'];
$subjectAddress = $_POST['subject_address'];
$legalDescription = $_POST['legal_description'];
$submit = $_POST['submit'];

$borrower_nameSet = isset($borrower_name) && empty($borrower_name);
$client_nameSet = isset($client_name) && empty($client_name);
$subjectAddressSet = isset($subjectAddress) && empty($subjectAddress);
$legalDescriptionSet = isset($legalDescription) && empty($legalDescription);


$send = 0;
echo "$send";

if(isset($submit))
	{echo "$send";	
	if(!$borrower_nameSet)
		{
		$send = 1;
		}
		else if($borrower_nameSet)
			{
			$error = "You must provide the borrower's name.";
			$send = 0;
			}
	if(!$client_nameSet)
		{
		$send = 1;
		}
		else if($client_nameSet)
			{
			$error .= "You must provide the client's name.";
			$send = 0;
			}
			
	if(!$subjectAddressSet && !$legalDescriptionSet)
			{
			$send = 1;
			}
		else if($subjectAddressSet && $legalDescriptionSet)
			{
			$error .= "You must provide either a subject address or legal discription.";
			$send = 0;
			}
	
	if(isset($error))
		{
  		echo "<p>  $error  </p>";
		}
	if($send == 1)
		{echo "$send";}
	/*	$to ="seymour.adam@gmail.com";
		$subject="Appraisal Order";
		$mailheaders="From: Smith-Parke & Co.<>";
		$msg="Borrower Name: $borrower_name\n";
		$msg.="Client Name: $client_name\n";
		$msg.="Attention: $attention\n";
		$msg.="Subject Address: $subject_address\n";
		$msg.="Legal Description: \n $legal_description\n";
		mail($to, $subject, $msg, $mailheaders);
		echo "<p><center><h2>Mail has been sent!</h2></center></p>";
		}*/

	}
?>

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 07-14-2005 19:55

Because you have a line break between your openeing and closing textarea tags, you're going to get a carraige return character or newline in there (not technically empty even if you can't see anything). Trim your whitespace first

empty(trim($legalDescription));



.:[ Never resist a perfect moment ]:.

Seymour
Bipolar (III) Inmate

From: K-town, FL, USA
Insane since: Jun 2002

posted posted 07-14-2005 20:23

I added the line
empty(trim($legalDescription)); and make the legal in the form look like this

code:
<tr>	
			<td><strong>Legal Description:</strong></td>
			<td><textarea name="legal_description" cols=30 rows=5></textarea></td>
		</tr>


but im still getting no results

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-14-2005 21:16

You are still checking for both the subject_address and the legal_description at the same time - there's no reason I can see to do so.

Do the checks seperately to amke sure you are getting what you want.

A textarea behaves no differently from any other form of input when it comes to retrieving the information.

Seymour
Bipolar (III) Inmate

From: K-town, FL, USA
Insane since: Jun 2002

posted posted 07-14-2005 21:44

The reason that I was doing them together was to save a step. The only reason that it should not send is if both of them are blank. If one or the other is filled in then all should be good. To test to make sure that this was not the problem i simplied the statement to just check the legal the same as i checked the rest of the input values and still cannot get the error message or allow it to make send = 1.

code:
$borrower_name = $_POST['borrower_name'];
$client_name = $_POST['client_name'];
$subjectAddress = $_POST['subject_address'];
$legalDescription = $_POST['legal_description'];
$submit = $_POST['submit'];
empty(trim($legalDescription));


$borrower_nameSet = isset($borrower_name) && empty($borrower_name);
$client_nameSet = isset($client_name) && empty($client_name);
$subjectAddressSet = isset($subjectAddress) && empty($subjectAddress);
$legalDescriptionSet = isset($legalDescription) && empty($legalDescription);




if(!$legalDescriptionSet)
			{
			$send = 1;
			}
		else if($legalDescriptionSet)
			{
			$error .= "You must provide either a subject address or legal discription.";
			$send = 0;
			}

Seymour
Bipolar (III) Inmate

From: K-town, FL, USA
Insane since: Jun 2002

posted posted 07-14-2005 22:13

Nevermind, the last post helped. I was just posting the updates to the wrong part of the server so it kept referring back to the old email order


Thank you so much for all the help

« BackwardsOnwards »

Show Forum Drop Down Menu