twilitegxa Posted November 18, 2013 Share Posted November 18, 2013 I have a site that is using some simple php to submit a form, but I would like to be able to have it automatically add the line breaks whenever I press enter when entering my text, as well as automatically turning any web address into a clickable link. Is this possible, and can anyone show me how please? Here is my code: <?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_spectac = "localhost"; $database_spectac = "database"; $username_spectac = "username"; $password_spectac = "password"; $spectac = mysql_pconnect($hostname_spectac, $username_spectac, $password_spectac) or trigger_error(mysql_error(),E_USER_ERROR); ?> <?php if(isset($_POST['eventDate'])){ $date = date('Y-m-d',strtotime($_POST['eventDate'])); } if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE tblEventCustom SET eventDate=%s, eventFile=%s, eventActive=%s, eventCost=%s, eventName=%s, eventFriendlyName=%s, eventDesc=%s WHERE eventId=%s", GetSQLValueString($date, "date"), GetSQLValueString($_POST['eventFile'], "text"), GetSQLValueString($_POST['eventActive'], "int"), GetSQLValueString($_POST['eventCost'], "int"), GetSQLValueString($_POST['eventName'], "text"), GetSQLValueString($_POST['eventFriendlyName'], "text"), GetSQLValueString($_POST['eventDesc'], "text"), GetSQLValueString($_POST['eventId'], "int")); mysql_select_db($database_spectac, $spectac); $Result1 = mysql_query($updateSQL, $spectac) or die(mysql_error()); } $colname_getEventDetails = "-1"; if (isset($_POST['eventId'])) { $colname_getEventDetails = $_POST['eventId']; } mysql_select_db($database_spectac, $spectac); $query_getEventDetails = sprintf("SELECT * FROM tblEventCustom WHERE eventId = %s", GetSQLValueString($colname_getEventDetails, "int")); $getEventDetails = mysql_query($query_getEventDetails, $spectac) or die(mysql_error()); $row_getEventDetails = mysql_fetch_assoc($getEventDetails); $totalRows_getEventDetails = mysql_num_rows($getEventDetails); mysql_select_db($database_spectac, $spectac); $query_getFileList = "SELECT * FROM tbl_eventFiles"; $getFileList = mysql_query($query_getFileList, $spectac) or die(mysql_error()); $row_getFileList = mysql_fetch_assoc($getFileList); $totalRows_getFileList = mysql_num_rows($getFileList); ?> <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.8.3.js"></script> <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> </script> <link rel="stylesheet" href="/resources/demos/style.css" /> <script> $(function() { $( "#datepicker" ).datepicker(); $(eventDate).datepicker({dateFormat: 'yy-mm-dd'}) }); </script> <? if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { ?><div align="center" >Event Updated <br> <a href="http://spectaculareventcenter.com/2012/index.php/component/content/article/2-uncategorised/22-editevents">Go back to event list. </a></div><? } ?> <form method="post" name="form1" action="<?php echo $editFormAction; ?>"> <table align="center"> <tr valign="baseline"> <td nowrap align="right">ID:</td> <td><?php echo $row_getEventDetails['eventId']; ?></td> </tr> <tr valign="baseline"> <td nowrap align="right">Event Date:</td> <td><input type="text" name="eventDate" value="<?php echo htmlentities($row_getEventDetails['eventDate'], ENT_COMPAT, ''); ?>" size="32" id="datepicker"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Event Active:</td> <td><p> <label> <input <?php if (!(strcmp($row_getEventDetails['eventActive'],"1"))) {echo "checked=\"checked\"";} ?> type="radio" name="eventActive" value="1" id="RadioGroup1_0"> Yes</label> <br> <label> <input <?php if (!(strcmp($row_getEventDetails['eventActive'],"0"))) {echo "checked=\"checked\"";} ?> type="radio" name="eventActive" value="0" id="RadioGroup1_1"> No</label> <br> </p></td> </tr> <tr valign="baseline"> <td nowrap align="right">Event Cost:</td> <td><input type="text" name="eventCost" value="<?php echo htmlentities($row_getEventDetails['eventCost'], ENT_COMPAT, ''); ?>" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Event Name:</td> <td><input type="text" name="eventName" value="<?php echo htmlentities($row_getEventDetails['eventName'], ENT_COMPAT, ''); ?>" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Display Name:</td> <td><input type="text" name="eventFriendlyName" value="<?php echo htmlentities($row_getEventDetails['eventFriendlyName'], ENT_COMPAT, ''); ?>" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Event Desc:</td> <td><textarea cols=32 rows=5 name="eventDesc" value="<?php echo htmlentities($row_getEventDetails['eventDesc'], ENT_COMPAT, ''); ?>" size="32"></textarea></td> </tr> <tr valign="baseline"> <td nowrap align="right">Event File:</td> <td><select name="eventFile"> <?php do { ?> <option value="<?php echo $row_getFileList['fileName']?>"<?php if (!(strcmp($row_getFileList['fileName'], $row_getEventDetails['eventFile']))) {echo "selected=\"selected\"";} ?>><?php echo $row_getFileList['fileName']?></option> <?php } while ($row_getFileList = mysql_fetch_assoc($getFileList)); $rows = mysql_num_rows($getFileList); if($rows > 0) { mysql_data_seek($getFileList, 0); $row_getFileList = mysql_fetch_assoc($getFileList); } ?> </select> <a href="http://spectaculareventcenter.com/2012/customCode/file_upload.php" target="_blank">Upload File</a></td> </tr> <tr valign="baseline"> <td nowrap align="right"> </td> <td><input type="submit" value="Update record"></td> </tr> </table> <p> <input type="hidden" name="MM_update" value="form1"> <input type="hidden" name="eventId" value="<?php echo $row_getEventDetails['eventId']; ?>"> </p> </form> <?php mysql_free_result($getEventDetails); mysql_free_result($getFileList); ?> Also, when the "event" is edited, all the other fields are auto-populate with the data from the database table, but the text area one is not auto-populated (i.e. it's blank instead). Can you tell me how to write this code properly so I have it working the way I need it? Any help is greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/284028-automatic-line-breaks-and-hyperlinks-in-text-area-field/ Share on other sites More sharing options...
requinix Posted November 18, 2013 Share Posted November 18, 2013 Line breaks? If you're using a textarea then you already have line breaks... As for the links, no, you need something more sophisticated than a textarea. Look into CKEditor, for instance. Quote Link to comment https://forums.phpfreaks.com/topic/284028-automatic-line-breaks-and-hyperlinks-in-text-area-field/#findComment-1458855 Share on other sites More sharing options...
twilitegxa Posted November 21, 2013 Author Share Posted November 21, 2013 Someone said there is a way to do it with some php code, but I didn't understand what they said. It's php within a Joomla plugin called Jumi, so I can't really add the CKEditor I don't think. And when we enter the text for example, like this into the text area: New Event Details Blah blah blah some more text here We're just pressing enter to add the line breaks, but when it saves it into the database, those line breaks either aren't saving or they aren't showing when we output the data. Can you see my code above and see which one it is and which I need to fix to solve the problem? For the text area, someone said I can either save it with nl2br when I put it into the database or when I display it use that, but I am not sure how to use it when displaying it. I think I had done it while submitting the data, but the problem is, I need to have the text displayed in the text area field when they edit the event and I am not doing it properly because it's not showing up. :-( Quote Link to comment https://forums.phpfreaks.com/topic/284028-automatic-line-breaks-and-hyperlinks-in-text-area-field/#findComment-1459386 Share on other sites More sharing options...
requinix Posted November 21, 2013 Share Posted November 21, 2013 (edited) those line breaks ... aren't showing when we output the data.That. save it with nl2br ... when I display itThat. htmlentities() the data first, then nl2br() to add HTML "line breaks" to the actual text line breaks. Looks like <?php echo nl2br(htmlentities($value, ENT_COMPAT, '')); ?>and outputs roughly New Event Details<br> <br> Blah blah blah<br> <br> some more text here Edited November 21, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/284028-automatic-line-breaks-and-hyperlinks-in-text-area-field/#findComment-1459410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.