Menu

&nbsp; & <br /> in text Area

Help
sam8599
2007-01-25
2013-06-03
  • sam8599

    sam8599 - 2007-01-25

    Even though the process.php code has

    $itemtitle=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $itemtitle);pt_register('POST','itemdesc');
    $itemdesc=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $itemdesc);pt_register('POST','itemsubdesc');
    $itemsubdesc=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $itemsubdesc);pt_register('POST','itemcode');

    still the output in SQL database has entries of &nbsp; & <br />.

    I am using the form to update my database.

    Please suggest

     
    • sam8599

      sam8599 - 2007-01-25

      My process.php

      <?php
      include("global.inc.php");
      $errors=0;
      $error="The following errors occured while processing your form input.<ul>";
      pt_register('POST','itemtitle');
      $itemtitle=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $itemtitle);pt_register('POST','itemdesc');
      $itemdesc=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $itemdesc);pt_register('POST','itemsubdesc');
      $itemsubdesc=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $itemsubdesc);pt_register('POST','itemcode');
      pt_register('POST','itemexp');
      pt_register('POST','itemimage');
      pt_register('POST','deptid');
      pt_register('POST','merchantid');
      pt_register('POST','dealcoupon');
      pt_register('POST','couponid');
      pt_register('POST','sortid');
      pt_register('POST','storeimage');
      if($errors==1) echo $error;
      else{
      $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
      $message="item title: ".$itemtitle."
      item desc: ".$itemdesc."
      item subdesc: ".$itemsubdesc."
      item code: ".$itemcode."
      item exp: ".$itemexp."
      item image: ".$itemimage."
      dept id: ".$deptid."
      merchant id: ".$merchantid."
      deal coupon: ".$dealcoupon."
      coupon id: ".$couponid."
      sort id: ".$sortid."
      store image: ".$storeimage."
      ";
      $message = stripslashes($message);
      mail("xxxxx","Form Submitted at your website",$message,"From: phpFormGenerator");

      $link = mysql_connect("localhost","xxxxx","xxxx");
      mysql_select_db("xxxx",$link);
      $query="insert into store_item (item_title,item_desc,item_subdesc,item_code,item_exp,item_image,dept_id,merchant_id,deal_coupon,coupon_id,sort_id,store_image) values ('".$itemtitle."','".$itemdesc."','".$itemsubdesc."','".$itemcode."','".$itemexp."','".$itemimage."','".$deptid."','".$merchantid."','".$dealcoupon."','".$couponid."','".$sortid."','".$storeimage."')";
      mysql_query($query);
      $make=fopen("admin/data.dat","a");
      $to_put="";
      $to_put .= $itemtitle."|".$itemdesc."|".$itemsubdesc."|".$itemcode."|".$itemexp."|".$itemimage."|".$deptid."|".$merchantid."|".$dealcoupon."|".$couponid."|".$sortid."|".$storeimage."
      ";
      fwrite($make,$to_put);

      header("Refresh: 0;url=/form1.html");
      ?><?php
      }
      ?>

       
    • TNTEverett

      TNTEverett - 2007-01-25

      If you follow this link http://www.php.net/manual/en/function.preg-replace.php
      you will see that the funct with replace "this" with "that". 
      preg_replace($this, $that)

      In your code the function replaces
      (\015\012)|(\015)|(\012)
      with
      &nbsp;<br />

       
      • sam8599

        sam8599 - 2007-01-25

        tnteveret1,

        I am getting &nbsp;<br /> in MYSQL database for item_title,item_desc,item_subdesc and not for the mail form, shouldn't be it in this part of the code...

        $link = mysql_connect("localhost","xxxxx","xxxx");
        mysql_select_db("xxxx",$link);
        $query="insert into store_item (item_title,item_desc,item_subdesc,item_code,item_exp,item_image,dept_id,merchant_id,deal_coupon,coupon_id,sort_id,store_image) values ('".$itemtitle."','".$itemdesc."','".$itemsubdesc."','".$itemcode."','".$itemexp."','".$itemimage."','".$deptid."','".$merchantid."','".$dealcoupon."','".$couponid."','".$sortid."','".$storeimage."')";
        mysql_query($query);
        $make=fopen("admin/data.dat","a");
        $to_put="";
        $to_put .= $itemtitle."|".$itemdesc."|".$itemsubdesc."|".$itemcode."|".$itemexp."|".$itemimage."|".$deptid."|".$merchantid."|".$dealcoupon."|".$couponid."|".$sortid."|".$storeimage."
        ";
        fwrite($make,$to_put);

        or I am wrong...

         
        • TNTEverett

          TNTEverett - 2007-01-25

          The very first thing that occurs is the variable replace this with that. 
          Every other function like write to the SQL database will write variables with the &nbsp<br/> appended to the end.  This is putting some html formatting into the variables for the email message.  If you were to save the email as text you would probably see these characters. 
          If you don't want these characters in the SQL then you must change the preg_replace for all, or create separate preg_replace just for the SQL function. 

           
          • Dave

            Dave - 2007-04-11

            Hi forum. Just starting to use phpformgenerator. Seems to be working quite well. I have this problem also. I am not writing this data to a database, only sending an email.

            I have a text area and when multiple lines are input, I get an email that looks like this:
            CLIENT FULL ADDRESS: addr 1&nbsp;<br />addr 2&nbsp;<br />addr 3&nbsp;<br />addr 4&nbsp;<br />addr 5

            If I follow the instructions from this thread, and changed the phpcode like this:
            $CLIENTFULLADDRESS=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $CLIENTFULLADDRESS)
            to $CLIENTFULLADDRESS=preg_replace("/(\015\012)|(\015)|(\012)/","", $CLIENTFULLADDRESS)

            then this is what I get in my email:
            CLIENT FULL ADDRESS: addr 1addr 2addr 3addr 4addr 5

            What I would like the email to look like is this:
            CLIENT FULL ADDRESS: addr 1
                                 addr 2
                                 addr 3
                                 addr 4
                                 addr 5
            or something similiar.

            Any help would be greatly appreciated.

            Thanks.

             
            • TNTEverett

              TNTEverett - 2007-04-11

              This is why when you subscribe to any automated email messages they ask if you prefer text or html. 
              The example you followed assumes html.  Your email appears to be expecting text and therefore does not understand the html part (it gets ignored).  You can format for text but then if you change your email to expect html you will have similar problems. 
              Decide who is going to receive the email, then how the email is expected from the email program used, then you can adjust the process.php file to send the right message. 
              You can send messages that work either way but not unless you want to do the programming yourself. 

               
              • Dave

                Dave - 2007-04-12

                Thanks for the quick reply tnteveret1.

                Just to make sure I understand you correctly. My email client (Mozilla Thunderbird) apparently expects to receive TEXT email messages. This is why I see the html code in the email.

                If I can configure my email client to accept HTML messages, the emails should display properly with the original code?
                $CLIENTFULLADDRESS=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $CLIENTFULLADDRESS)

                If I keep my email client configuration as is (text) then I would have to edit the original code and format the data properly using php code in the process.php file? (Right now it just concatenates the lines for a text area field.)

                Is this correct?

                Thanks in advance.

                 
                • TNTEverett

                  TNTEverett - 2007-04-12

                  Without actually knowing your exact configuration I am just guessing.  Take my input and investigate what you have to see if it makes sense. 

                   
                  • Dave

                    Dave - 2007-04-12

                    Thanks again for the quick reply tnteveret1.

                    Okay, by default Both Mozilla Thunderbird and Outlook Express (security hole posing as a email client) expect html messages. So if I have this code in process.php in regards to a text area field:
                    $CLIENTFULLADDRESS=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $CLIENTFULLADDRESS)
                    the html tags should not display.

                    However, they do display. (In thunderbird you can easily choose to display messages in Original HTML, Simple HTML, or Plain text.) The default is Original HTML. So if I use the above code, why would I get the following displayed when viewing the message using Original HTML?
                    CLIENT FULL ADDRESS: add 1&nbsp;<br />add 2&nbsp;<br />add 3

                    (where add 1 is the first line of data)
                    (where add 2 is the second line of data)
                    (where add 3 is the third line of data)

                    If you create a 1 field form with that field being a text area of 3 rows by 30 columns, entered in 3 lines of data and sent it via email, what do you see?

                    I am not trying to be an ass. I really like the software. I just want to figure out why I am seeing the html tags instead of the tags being interpreted correctly. I want to be part of the solution. I stand ready to do whatever it takes.

                    Or am I the only one experiencing this result?

                    Thanks,
                    Dave

                     
                    • TNTEverett

                      TNTEverett - 2007-04-12

                      Send me a link to a form1.html file.  Email me the process.php file, a bitmap sample of what you see in your email, and a description of what you would like to see instead. 
                      I will analyze the program against your result and tell you what you need to do for any form in the future to produce the desired result. 

                       
                      • Dave

                        Dave - 2007-04-13

                        TNTEverett,
                        Thank you for your reply.
                        I sent you an email with all the elements you requested.
                        Please let me know if you don't get the email.
                        Thanks.
                        Dave

                         
                        • Dave

                          Dave - 2007-04-13

                          Whoops,
                          the message came right back complaining about the size was too large. Sorry for being such a noob, but how do I supply you the requested items and attachments?
                          Dave

                           
                          • TNTEverett

                            TNTEverett - 2007-04-13

                            OK I made two changes. 

                            1.) Move the line
                            $textareabox=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $textareabox);
                            To the very end of the php section (just above the line containing "?>").  This takes the form data and replaces the text carriage return and line feeds with html equivalent tags.  This works perfectly for the Thank You page but screws up your text email. 
                            Moving it to the end allows the email to be processed first before making the substitution for the html thank you page. 

                            2.) I added a line feed to the email message so that line 1 is not a continuation of the text box name label. 

                             
    • sam8599

      sam8599 - 2007-01-25

      My scripting knowledge is level of novice... please guide

      what i see

      $itemtitle=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $itemtitle);pt_register('POST','itemdesc');
      $itemdesc=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $itemdesc);pt_register('POST','itemsubdesc');
      $itemsubdesc=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $itemsubdesc);pt_register('POST','itemcode');

      already there ..... what else I need to do to not show in MYSQL.

      Please be patient.

      TIA

       
      • TNTEverett

        TNTEverett - 2007-01-25

        If you don't mind the effects on email change each line to the following.
        $itemtitle=preg_replace("/(\015\012)|(\015)|(\012)/"," ", $itemtitle);pt_register('POST','itemdesc');
        $itemdesc=preg_replace("/(\015\012)|(\015)|(\012)/"," ", $itemdesc);pt_register('POST','itemsubdesc');
        $itemsubdesc=preg_replace("/(\015\012)|(\015)|(\012)/"," ", $itemsubdesc);pt_register('POST','itemcode');

         
        • sam8599

          sam8599 - 2007-01-25

          Thankyou sir,

          It worked.....

          Another checking question..... can you guide me where I can get information to how I can password protect the form file

          What I want to do is

          1. Can only sign-in the form with a password
          2. The password is either remembered as a cookie or session
          3. Once the data is submitted it redirects back to form page

          BUT

          1. I don't need to enter the password again, till I close the Browser or set a cookie expiration time.

          Appreciate all your help and time.

          regards

           
          • TNTEverett

            TNTEverett - 2007-01-25

            It is best to do this by password protecting the whole directory.  This way no one can access anything in the directory at all without a password. 
            I do this through my hosts control panel interface.  It works very well.

             
            • sam8599

              sam8599 - 2007-01-26

              Thnakyou Sir..... once again for the suggestion

              I used .htpassed and .htaccess and it works...great

               
    • Hayley Richards

      Hayley Richards - 2007-01-27

      Hi,

      All my data goes to an email address from the form. I get this as the message & voice description: [quote]Hello, this is Vicky from Spain.&nbsp;<br />I hope you like my demos
      ...&nbsp;<br />Castillian-European[/quote]

      My code is below - how can I get it so that when they write with paragraphs, it appears with spaces, rather than all one blob with "&nbsp;<br />" inbetween. Thank you all!!!

      <?php
      include("global.inc.php");
      $errors=0;
      $error="The following errors occured while processing your form input.<ul>";
      pt_register('POST','Name');
      pt_register('POST','Email');
      pt_register('POST','Message');
      $Message=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Message);pt_register('POST','Voicedescription');
      $Voicedescription=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Voicedescription);pt_register('POST','ISDN');
      pt_register('POST','Sex');
      $Demo1=$HTTP_POST_FILES['Demo1'];
      $Demo2=$HTTP_POST_FILES['Demo2'];
      $Demo3=$HTTP_POST_FILES['Demo3'];
      $Demo4=$HTTP_POST_FILES['Demo4'];
      $Demo5=$HTTP_POST_FILES['Demo5'];
      if($Name=="" || $Email=="" || $Message=="" || $Sex=="" || $Demo1=="" ){
      $errors=1;
      $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
      }
      if(!is_uploaded_file($HTTP_POST_FILES['Demo1']['tmp_name'])){
      $error.="<li>The file, ".$HTTP_POST_FILES['Demo1']['name'].", was not uploaded!";
      $errors=1;
      }
      if($HTTP_POST_FILES['Demo2']['tmp_name']==""){ }
      else if(!is_uploaded_file($HTTP_POST_FILES['Demo2']['tmp_name'])){
      $error.="<li>The file, ".$HTTP_POST_FILES['Demo2']['name'].", was not uploaded!";
      $errors=1;
      }
      if($HTTP_POST_FILES['Demo3']['tmp_name']==""){ }
      else if(!is_uploaded_file($HTTP_POST_FILES['Demo3']['tmp_name'])){
      $error.="<li>The file, ".$HTTP_POST_FILES['Demo3']['name'].", was not uploaded!";
      $errors=1;
      }
      if($HTTP_POST_FILES['Demo4']['tmp_name']==""){ }
      else if(!is_uploaded_file($HTTP_POST_FILES['Demo4']['tmp_name'])){
      $error.="<li>The file, ".$HTTP_POST_FILES['Demo4']['name'].", was not uploaded!";
      $errors=1;
      }
      if($HTTP_POST_FILES['Demo5']['tmp_name']==""){ }
      else if(!is_uploaded_file($HTTP_POST_FILES['Demo5']['tmp_name'])){
      $error.="<li>The file, ".$HTTP_POST_FILES['Demo5']['name'].", was not uploaded!";
      $errors=1;
      }
      if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
      $error.="<li>Invalid email address entered";
      $errors=1;
      }
      if($errors==1) echo $error;
      else{
      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Demo1']['name'];
      $image_list[6] = $image_part;
      copy($HTTP_POST_FILES['Demo1']['tmp_name'], "files/".$image_part);
      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Demo2']['name'];
      $image_list[7] = $image_part;
      copy($HTTP_POST_FILES['Demo2']['tmp_name'], "files/".$image_part);
      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Demo3']['name'];
      $image_list[8] = $image_part;
      copy($HTTP_POST_FILES['Demo3']['tmp_name'], "files/".$image_part);
      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Demo4']['name'];
      $image_list[9] = $image_part;
      copy($HTTP_POST_FILES['Demo4']['tmp_name'], "files/".$image_part);
      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Demo5']['name'];
      $image_list[10] = $image_part;
      copy($HTTP_POST_FILES['Demo5']['tmp_name'], "files/".$image_part);
      $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
      $message="Name: ".$Name."
      Email: ".$Email."
      Message: ".$Message."
      Voice description: ".$Voicedescription."
      ISDN: ".$ISDN."
      Sex: ".$Sex."
      Demo 1: ".$where_form_is."files/".$image_list[6]."
      Demo 2: ".$where_form_is."files/".$image_list[7]."
      Demo 3: ".$where_form_is."files/".$image_list[8]."
      Demo 4: ".$where_form_is."files/".$image_list[9]."
      Demo 5: ".$where_form_is."files/".$image_list[10]."
      ";
      $message = stripslashes($message);
      mail("sales@airtalentonline.co.uk","Air Talent Online Demo Submit Form",$message,"From: phpFormGenerator");

      header("Refresh: 0;url=http://http://www.airtalentonline.co.uk/thankyoudemosubmit.htm");
      ?><?php
      }
      ?>

       
      • TNTEverett

        TNTEverett - 2007-01-27

        Find the variables you need to use in your message and change the
        =preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />",
        to
        =preg_replace("/(\015\012)|(\015)|(\012)/"," ",

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.