⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

paragraph tag get attached in text field



Nitin Thokare

Nitin Thokare
  • profile picture
  • Member

Posted 29 May 2014 - 07:25 AM

I'm using text field to get address input from user. When user fills the details and submit, I see in the database table that paragraph tag gets attached to the address. e.g. if entered address is as below:

Aurangabad

It gets stored into data table as: (row from database shown in attached file)

<p>Aurangabad<p>

Why is this happening? How can I avoid this?

 

 


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 29 May 2014 - 20:49 PM

Hi, why you souldn't use field_type(field,'string')? I think it dependens what field type you using in database? so what field type in your database have "address"?


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 29 May 2014 - 22:56 PM

Well this is common.. functionality of the editor .. when it submitts .. it by default adds up the p tag.. what u can do on server side.. when u recieve the submitt.. or say b4 u insert the same.. remove the p tags from begining and end... thats simpler way to avoid it.

 

Happy GCing :)


titu

titu
  • profile picture
  • Member

Posted 03 September 2014 - 19:29 PM

Needed to remove <p> tags so I share the simple code:

 

 
$crud->callback_before_insert(array($this,'trimp'));
$crud->callback_before_update(array($this,'trimp'));

 

 
public function trimp($row) {
 $row['field_one'] = ltrim(rtrim($row['texto_completo'],"</p>"),"<p>");
 $row['field_two'] = ltrim(rtrim(trim($row['pie']),"</p>"),"<p>");
 return $row;
}        

titu

titu
  • profile picture
  • Member

Posted 03 September 2014 - 20:18 PM

As ltrim and rtrim uses the second parameter as characters and not as words perhaps this one is more useful:

 

 $row['field_one'] = preg_replace('/^(<p>)|<\/>$/', '', trim($row['texto_completo']));
 $row['field_two'] = preg_replace('/^(<p>)|<\/>$/', '', trim($row['pie']));