WordPress.org

Ready to get started?Download WordPress

Forums

Automatically add line breaks and hyperlinks from textarea field? (1 post)

  1. twilitegxa
    Member
    Posted 8 months ago #

    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? (i know i'm doing it the old fashioned way)

    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">&nbsp;</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);
    ?>

Reply

You must log in to post.

About this Topic

Tags