2

I having a problem while I convert a php variable to javascript in React.

Here's the code (the content is in spanish):

var insertar = "<?php echo $insertar; ?>";

var phpCodeInsertar = React.createClass({

 render : function(){

     if(!insertar){

         return(

             <center id='descripcion-registro-fail'>
                 <h1 id='dr-fail-h1'>Error al registrarte</h1>
                 <ul id='dr-fail-ul'>
                     <li>&middot Comprueba que has escrito bien tus datos.</li>
                     <li>&middot Asegurate de que no estás registrado(en caso contrario no puedes hacerlo de nuevo).</li><br></br>
                     <li id='dr-fail-ul-li'>Si ya has realizado los pasos anteriores y el problema sigue apareciendo, ponte en contacto con el <a id='dr-fail-a'>soporte</a>.</li>
                 </ul>
             </center>

         ); 

     } else {

         return(

         <center id='descripcion-registro'>
             <h1 id='dr-h1'>Gracias por registrarte.</h1>
             <p id='dr-p'>
                 Se ha enviado un correo de confirmación a tu email,<br></br>
                 entra en el enlace que hay en él y sigue las instrucciones para<br></br>
                 confirmar tu cuenta.
             </p>
         </center>

         );

     }

 }

});

My problem is: When I render the page I see the message: Uncaught TypeError: Cannot read property 'replace' of undefined.

I think React detects "insertar"(a bool php variable) like undefined.

How can I make React detect "insertar" correctly?

nilgun
  • 10,460
  • 4
  • 46
  • 57
Valeo
  • 21
  • 1
  • 5
  • From the error, it sounds like you're trying to call .replace() on an undefined variable, but I'm not seeing that code. I don't think it's a problem with insertar based on what you posted. Even if it was empty it should be cause in the if statement. Example: http://jsfiddle.net/yq4hvyxj/ – DontMindMe Feb 04 '15 at 20:45
  • Related: http://stackoverflow.com/questions/23354554/uncaught-typeerror-cannot-read-property-replace-of-undefined-in-grid and http://stackoverflow.com/questions/23259064/uncaught-typeerror-cannot-read-property-replace-of-undefined – DontMindMe Feb 04 '15 at 20:47

1 Answers1

2

It is not a problem with your php->javascript variable

React Class(component) name should be Camel Cased starting with Uppercase

so change

phpCodeInsertar
to this:
PhpCodeInsertar
pkarc
  • 417
  • 5
  • 9