Simplifying Form Validation with Eclipse Backreferences
I'm in awe of Eclipse and the productivity it affords me. Today's revelation comes as I look at a form with 43 fields defined by our graphics guy and a need to set the value="" attribute to the previously submitted value if it exists. With Eclipse and backreferences in the find/replace I was able to do it in one shot.
All my input fields were defined as
<input name="fldname" ... blah, blah, blah >
- Take a copy of your code in case this blows up on you
- Ctrl+F opens the find / replace window. Set the find string to
name="(.*?)"
This finds the name="" attribute and whatever is between the quotes is stored as a backreference number 1 - Set the replace string to
name="$1" value="#attributes.$1#"
This says we are going to output two attributes in place of the one and for the value we are adding some CF code around the backreference $1 also. - Check the regular expressions box
- Click find to be sure that your regex finds a good first match.
- Click replace to replace just one occurence to check that it outputs in the way you want (it's easier to undo one mistake vs 43)
- If all is good hit replace all