Topic awaiting preservation: if statement to check <textarea></textarea> for text (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: K-town, FL, USA |
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"; }
|
Maniac (V) Inmate From: under the bed |
posted 07-08-2005 07:07
For one, $_POST[legal_description] should have quotes: $_POST['legal_description'] |
Maniac (V) Mad Scientist From: Rochester, New York, USA |
posted 07-08-2005 16:12
isset() is also your friend. 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>"; }
|
Maniac (V) Inmate From: under the bed |
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.";
code: } else if (!$legalDescriptionSet){ $error = "You must provide a valid legal description."; } else if (!$subjectAddressSet) { $error = "You must provide a valid subject address.";
|
Maniac (V) Mad Scientist From: Rochester, New York, USA |
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.";
|
Bipolar (III) Inmate From: K-town, FL, USA |
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 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>"; }*/ } ?> |
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
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 |
Bipolar (III) Inmate From: K-town, FL, USA |
posted 07-14-2005 20:23
I added the line code: <tr> <td><strong>Legal Description:</strong></td> <td><textarea name="legal_description" cols=30 rows=5></textarea></td> </tr>
|
Maniac (V) Inmate From: under the bed |
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. |
Bipolar (III) Inmate From: K-town, FL, USA |
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; } |
Bipolar (III) Inmate From: K-town, FL, USA |
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 |