I have integrated codepress (codepress.org) into the create and edit form for a custom node type I created. It's a very slick javascript based editor for dynamically numbering and highlighting php, css etc text.

The codepress editor shows up in the form textarea, but I'm not sure how I can get the text back into my node. For example, typically I would have this rendered on the client:

<textarea cols="60" rows="20" name="qform" id="edit-qform"  class="form-textarea resizable required codepress php"> [PHP CODE HERE FOR EDITING]

With codepress, the textarea is replaced on load, so the 'generated' source is:


<iframe src="http://govirtual.bpweb.bp.com/sites/all/modules/qdrupal/codepress/codepress.html?language=php&amp;ts=1179755957881" style="border: 1px solid gray; height: 402px; width: 661px; visibility: visible; position: static; display: inline;" frameborder="0"></iframe><textarea style="overflow: auto; display: none;" disabled="disabled" cols="60" rows="20" name="qform" id="edit-qform_cp" class="form-textarea resizable required codepress php processed"> [ORIGINAL CONTENT HERE]

From the docs, it says that the edited code can be gotten from the codepress editor with :

textarea_id.getCode()

So it sounds like I would need some way to do pre submit client side validation, where I could get the text and put it back in the origianl textarea. Can the Drupal FormAPI handle this scenario?

Comments

asohn’s picture

If you're finding yourself doing a lot of php coding, and you can live without the syntax highlighting, you can edit the system.css file (modules/system/system.css)

html.js .resizable-textarea textarea {
  margin-bottom: 0pt;
  width: 100%;
  display: block;
  font-family: courier new;
}

to alter the way the textareas display when editing a node (or anything else that uses the class "form-textarea resizable" for that matter).
I recommend you make a system.css.bak before making any changes.
This change along with the use of Notepad++ allows for local backups of more time consuming and larger php segments. The only downside (if you can call it that) is that Notepad++ indention of lines does not display consistently in a web page's textarea.
I'm sure that what you are asking isn't to far-fetched, I found myself looking into it but not too deeply. I'll let you know if I come up with anything.
Something else worth noting is that there are still bugs in the current version of CodePress. This will be a very nice module if/when it is complete.

meecect’s picture

I ended up modifying the codepress source a bit. I added an event handler that manages to 'unwind' the changes on submit. This takes the dom changes and puts them back the way they were on load, and runs a codepress function to pull the edited content from the iframe and put it back in the original textarea. It works quite well.

Right now it is integrated into my module that does a lot of other stuff, but I have considered factoring it out into a separate codepress modeule. Would there be interest in that? The only complication I have noticed is that tinymce can step all over it, and since tiny has some inflexible rules for telling it where to show up, it can be a pain.

asohn’s picture

Ya I'd be interested in playing with it as a separate module. If not a separate module, what are some of the other features it would have as a module?