
etheracide
journeyman
Feb 25, 2003, 8:50 PM
Post #5 of 5
(10750 views)
|
Re: [davorg] double replacement
[In reply to]
|
Can't Post
|
|
I will write out an example of my code. Most of it is not needed for this problem so I will write the most pertinent of info to this problem. i will also explain what the above code did for me. This 'program' is multiple scripts. It is supposed to allow a user to create, preview, and then save their resume. Once they finish entering their info, they hit the submit button which takes them to the preview. The preview script captures the information from the following page and if a field had a value, it prints the text for it and then it's value. Simple enough. The second script then has a submit button which the user will click if they are satisfied with how the resume looks. The save script will save the html to an html file named $username.html and also takes the information and saves it to a database. The database is named $username.dat and features the password, E-mail address and all of the information that goes into the resume. This of course is used for password verification upon login, sending of mails to their E-mail address, and when the user edits their resume, the editing script pulls the info from the database to 'pre-fill' the form. Well the info isn't being saved properly in the database and therefore can't be put into the resume editor properly. The resume creating/editing script has textareas such as a box for references. The user should be able to enter multiple references into this one box. They should be able to 'return' for each new line such as name (line one), street address, town state and zip (line three) how long they've known them (line four) and contact number (line five). And then double 'return' to start the next reference. I am not concerned with the number of lines exactly...I just want the user to be able to use carriage returns. Now, the preview script should use this info in two ways. It should take out the newlines and replace them with <br /> (to be compliant with HTML4) for the part where it saves the HTML to the html file. But, the script should strip out the newlines and and place any 'symbol' (except for pipe since I use that for the rest of my database) where the carriage returns are. This is done so that in the creating/editing code, I can make the script then replace the symbols with newlines so that the references will appear correctly in the textarea. Here's my attempt to show the important information of each script. The resume creating/editing script with textarea and taking symbol (I decided to go with a number sign JUST FOR AN EXAMPLE here) out and replacing it with newlines to make the formatting correct in the textarea. The value for references is pulled from the $username.dat but I am leaving that out of the code. $references =~ s/#/\n/g; print "<tr><td><span class=text>References:</span></td><td> <textarea name=references cols=25 class=input>$references</textarea></td></tr>"; _______________________________________________________________ Now the preview script takes the references and other information and creates an HTML page so that the user can see how their resume will look as it stands. You will notice the use of hidden fields to send the values to the script which will save the info. The value of references being passed to the preview script will have newlines in it. I want to turn those newlines into HTML line breaks (<br />) to properly format it for the HTML document that will be created. Because of the formatting done to the the value of $references done in the previous step, the value of $references still holds those <br />'s. Those should be kept in the value for saving the HTML because they are needed to format them in the html page. But there's a save_customer subroutine and there has to be formatting there that will not mess up the database, but also allow for the editing script to know that a newline goes there in the textarea. $references = $christophersnyder->param('references');&save_customer;if ($references eq "") { print ""; }else{ print "<tr><td><span class=text>References:</span></td><td><span class=body>$references</span></td></tr>"; } sub save_customer { $references =~ s/<br \/>/#/g; open(CUST, ">data/$customer.dat"); print CUST "$password|$email|$references"; close(CUST); }
|