PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Strip line-breaks during submission?

  1. Is there a way to strip line breaks from a field before I use the data submitted?

    We've got a basic form - but it has to pass alot of information as a query string, and there is a paragraph area that often people type "enter/enter" to get two line breaks. Is there a function I can use to REMOVE those during submission?

    Posted 11 years ago on Thursday July 19, 2012 | Permalink
  2. David Peralty

    Hi there, I don't know that you should be passing a paragraph of text through a query string as there are potential issues with that, and the string, despite reformatting won't ever get those line breaks back. You could try using the gform_pre_submission hook to strip them out using something like the script found here:

    http://php.net/manual/en/function.str-replace.php

    I think they might be hiding as /r and /r/n in the text that is submitted, but I'm not certain. Instead of replacing them with html line breaks, you would want to replace them just with a space or something.

    Posted 11 years ago on Thursday July 19, 2012 | Permalink
  3. I know it's not "ideal" - but for this application it's really not an issue passing it as a query string. The only real issue is the line breaks! Thanks for the script though - I'll let you know how it turns out

    Posted 11 years ago on Thursday July 19, 2012 | Permalink
  4. So do I past the code in functions.php?

    add_action("gform_pre_submission", "strip_linebreaks");
    function strip_linebreaks($form){
    	$_POST["input_11"] = preg_replace("/\r?\n/", "", ($_POST["input_11"]);
    }
    Posted 11 years ago on Thursday July 19, 2012 | Permalink
  5. David Peralty

    Yes, it would go in your functions.php file. And you might want to put a space in the second area for your preg_replace. Also, what is the question mark in your carriage return and new line call?

    Posted 11 years ago on Thursday July 19, 2012 | Permalink