pcoxygen Posted September 1, 2009 Share Posted September 1, 2009 I know absolutely nothing about PHP script. But I do have a little problem with what I have done in some very easy code. I'm creating an HTML user Form that when Submitted, it gets posted to a PHP page to print on screen what the user typed in the form fields. PROBLEM: With my existing PHP script, it writes a blank line where no data is in the HTML field. I don't want that. I want the results to skip or ignore the HTML field that was left blank by the user. The HTML form page (form.html) is this: <html> <body> <form action="label_print.php" method="get"> Your Name:* <input name="name" type="text" /> <br /> Company: <input name="company" type="text" /> <br /> Address: * <input name="address1" type="text" /> <br /> Address: <input name="address2" type="text" /> <br /> City:* <input name="city" type="text" /> <br /> State:* <input name="state" type="text" /> <br /> Zip Code:* <input name="zip" type="text" /> <br /> <br /><br /> <input type="submit" value="Make Label Now" /> </form> </body> </html> The PHP to print the Form fields (label_print.php) script is this: <html> <body> <?php /* * This will print whatever the user put into the form on the form.html page. */ $name = $_REQUEST['name']; $company = $_REQUEST['company']; $address1 = $_REQUEST['address1']; $address2 = $_REQUEST['address2']; $city = $_REQUEST['city']; $state = $_REQUEST['state']; $zip = $_REQUEST['zip']; echo "From:<br />". $name ."<br />". $company ."<br />". $address1 ."<br />". $address2 ."<br />". $city .", ". $state ." ". $zip .""; ?> </body> </html> A working example of the above can be found here: http://www.certifiedlaptoprepair.com/shipping_label/form.html So can anyone offer any advice what I need to add to the PHP to make it ignore blank field in the Form? Any other suggestion are also appreciated (if I have typed some wrong PHP code, or how to make it more efficient). Thanks. Link to comment https://forums.phpfreaks.com/topic/172657-ignore-empty-fields-in-form-how/ Share on other sites More sharing options...
MasterACE14 Posted September 1, 2009 Share Posted September 1, 2009 if(strlen(isset(!empty($_REQUEST['something']))) > 0) { $something = $_REQUEST['something']; echo "Something:<br />".$something; } else { echo "Nothing was entered into ".$_REQUEST['something']."!"; } Link to comment https://forums.phpfreaks.com/topic/172657-ignore-empty-fields-in-form-how/#findComment-910111 Share on other sites More sharing options...
pcoxygen Posted September 1, 2009 Author Share Posted September 1, 2009 Ok, I thought I found the answer somewhere on the web. But what MasterACE14 posted is better. This is what I found: Removing the whole PHP line starting with echo (post above). if (!empty($name)) { print "$name<br>"; } However, what you have provided is really what I want because it has the "else", which alerts the user if there is a required field. Awesome! Thank you for your time and skill. I wish I knew PHP like you guys. It's such a valuable language. Thanks again. Link to comment https://forums.phpfreaks.com/topic/172657-ignore-empty-fields-in-form-how/#findComment-910115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.