No announcement yet.

CR causing a variation of the sc_redir not working in a form app - including a fix

  • Filter
  • Time
  • Show
Clear All
new posts

  • CR causing a variation of the sc_redir not working in a form app - including a fix

    Hi everyone,
    Have been working on a bunch of 'wizards', which are basically form apps strung together. I do this because I don't want to overwhelm the user with one giant form to fill out on one screen. So I basically just display 3 or 4 fields grouped logically together on each wizard screen, and use the form's onAfterUpdate event to do a sc_reidr to the next form app in the wizard (and rename the Update button to 'Next Step' and the Exit to 'Previous Step'). These always work great for my projects.

    Anyway, of course I had to run into a 'bug' that caused me about 4 hours of debugging, so I am sharing this here in case anyone else every confronts this issue. It was tricky as it mimicked the situation already well documented in the forum and mentioned in the SC help docs, about having to do a c_commit_trans() in a form before doig a sc_redir. This is a different issue. Not sure why it happens - perhaps it screws up something in the generated code. But it is very reproducible in SC 8 version 8.00.0043.


    IF you have a text field in a form, and you have CR (might be LF too) in the text (either from copy and paste text that already had it OR with caused by hitting ENTER key when typing) and you then try to do a sc_redir in the onAfterUpdate event, it fails to move on. The app just stays on teh screen. There is no error, even when in debug mode. Does not matter if the database field is text or varchar(1000) or something.

    I started with a multi-line text field, but also couldl cause the issue even with a single line text field (If I pasted text in with a CR/LF). If I cleared the field content or just typed in a short line of text, the sc_redir would work. It was the content of the field that was causing it!!!!!!!! I had been using the app with no issues for months but it wasn't until someone entered the content this way that it failed.

    This error is not caused by the sc_commit_trans() requirement as specified in the help documentation. I tried it with both the commit and without - same issue. It happens regardless if you have that in your code or not.


    So, to fix I added this code to the onValidate event:
    {Description} = str_replace (array("\r\n", "\n", "\r"), ' ', {Description});
    Then in the onAfterUpdate event this worked OK:
    // go to next step
    sc_commit_trans(); // MUST do in a form before redir

    NOTE: I didn't have time to closely investigate if it was CR or LF or what was causing it precisely. Nor do I have time to look at generated code. I just wanted to help anyone who had this combination of conditions in the future. Perhaps SC can add this to a list to look at later.

    Anyway, I hope this helps anyone in the future who might be having weird issues again with sc_redir and has a multi-line text field in the form in question.