buntus00 Posted December 18, 2009 Share Posted December 18, 2009 I'm a newbie to php and have a volunteer project to create a jobs board. It works on the same principle as a guest book where you would add comments, except you post jobs. However, I have a formatting problem with textarea boxes. People who post jobs need a minimum of styling, e.g. bullets, bold etc. Before I go into that, the ultimate solution would be to incorporate a text editor into the php that could handle multiple textarea boxes. I've reviewed a few, TinyMCE, fck editor, etc, but they are javascript-based, (I don't know js) -and full detailed and accurate instructions on how to incorporate these with php are scant. If anyone knows of a piece of freeware that would do the trick, please advise with clear instructions, but, -it has to be easy. Ok, Formatting issue: New line breaks are not recognised by the textarea when the Enter key is pressed. e.g. If I add bullets to the textarea, (by adding ASCII characters = • -essential for job descriptions) then press enter at the end of the line, -yes, each bullet shows on a new line within a textarea before posting, but... after posting, when the info is pulled from of the db again and displayed via body.html, it appears just as a long string. I've included here just the stripped-down code relevant to the issue. What have I tried? Experiments with a wrap ="hard" attribute within the form, I've tried nl2br but don't know with precision how and where to implement it so it works. I just tried it in the posting file (postjob.php) That ain't working. Also I just don't know how two apparently conflicting concepts can be resolved. On the one hand, I understand I need to prevent people inserting raw html into the db -and I had previously used stripslashes for that (plus mysql_real_escape_string against SQL injection) and on the other hand, I need to be able to put line breaks in there, (and I understand nl2br converts to a <br /> anyway). But we shouldn't have html in there anyway, right? I don't get it. I also have a job editing section (a form), where people can pull up and edit their jobs. When I pull up sample jobs from the db, using $_GET. -again it's all visually on one line plus it's peppered with horrible <br> tags that job owners should not be seeing. This form is presumably only pulling out of the db what is already in there, so the <br> tags are getting in there. Any help on this from anyone, it's driving me nuts. (But please don't refer me to php.net, -it's an esoteric quagmire for beginnners.) Thanks! ------------------------------------------------------------ Sample code: How it works Postform.php = job posting form <div style = margin-left:101px;> <br /> <strong>Detailed description:</strong> <br /> <textarea name ="job_description" rows="5" cols="95" wrap ="hard" ></textarea> <br /> <br /> <strong>Required skills: </strong> <br /> <textarea name ="required_skills" rows="5" cols="95" wrap ="hard"> </textarea> <br /> <br /> <strong>Application instructions:</strong> <br /> <textarea name="job_app_instructions" rows="4" cols="95" wrap ="hard"></textarea> </div> ________________________________________________________ Postjob.php = posts the jobs //Standard input boxes $job_title= mysql_real_escape_string($_POST['job_title']); $job_number = mysql_real_escape_string($_POST['job_number']); $pay_rate= mysql_real_escape_string($_POST['pay_rate']); //Textarea input boxes $job_description= nl2br($_POST['job_description']); $required_skills= nl2br($_POST['required_skills']); $job_app_instructions= nl2br($_POST['job_app_instructions']); ________________________________________________________ body.html = pulls jobs from db (job display page) $get= mysql_query ("SELECT * FROM posted_jobs ORDER BY ID "); while($row = mysql_fetch_array($get)) { $job_title= $row ['job_title']; $job_number= $row ['job_number']; $job_type= $row ['job_type']; $pay_rate = $row ['pay_rate']; $job_location = $row ['job_location']; $date_posted = $row ['date_posted']; $job_description= $row ['job_description']; $required_skills= $row ['required_skills']; $job_app_instructions= $row ['job_app_instructions']; $add_notes= $row ['add_notes']; echo " <hr> .<br /> <strong> $job_title </strong><br /><br /><br /> <strong>Job number: $job_number </strong><br /> <strong>Job type: $job_type</strong> <br /> <strong>Pay rate: $pay_rate</strong> <br /> <strong>Location: $job_location </strong> <br /> <strong>Date posted: $date_posted </strong><br /> <br /> <strong>Job description: </strong> <br /> $job_description <br /> <br /> <strong>Job requirements: </strong> <br /> $required_skills <br /> <br /> <strong>Application instructions: </strong> <br /> $job_app_instructions </strong> <br /> <br />"; if (empty($row ['add_notes'])) { } else echo "<strong>Additional notes: </strong> <br /> $add_notes <br /> <br />"; Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 18, 2009 Share Posted December 18, 2009 You can use strip_tags to remove any HTML along with mysql_real_escape_string. After you removed the HTML you should use nl2br BEFORE entering it into the database. What this function does is turns the 'invisible' \n's into <br/>'s for the database, which can obviously later output and return the linebreaking as it was. it's an esoteric quagmire for beginnners. Not a single question can not be answered by looking in the documentation, The examples are purely what make it easy for beginners. I'd recommend you look further up tutorials on how to perform these tasks, It's shouldn't be too hard. Quote Link to comment Share on other sites More sharing options...
buntus00 Posted December 19, 2009 Author Share Posted December 19, 2009 Thanks for the reply. I work hard before I come here. I was looking for a concrete way, to implement nl2br or any other comparable solution. I'm happy for any help I can get. If you can't answer my question, that's cool, too. 'Not a single question can not be answered by looking in the documentation' You realize you just negated the reason for the very existence of this forum, right? Quote Link to comment 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.