Input is "Cutting" what comes after space with PHP

Asked

Viewed 195 times

-3

I have a registration change screen. The information that will be changed I bring to an input field, allowing the user to move if necessary.

however, a problem occurs if the word is separated by 'space', ie if the user type "Olá mundo", only goes to input field "Olá".

HTML:

<a a class="arib">Origem: </a><input type="text" maxlength="40" placeholder="Origem" value=<?php echo $Origem; ?> name="origem" style="width:50px;"/>

PHP:

<?php
$Origem = "Olá Mundo";
?>
  • Put "var_dump($Origin)" in your code just before you use the variable. With this you will be able to know better if the problem is at echo time or if the variable is being distorted. If possible paste here your PHP code from the time of creation of the variable until the use of it.

  • There it is coming out full "Hello World", but the input keeps coming out only "Hello"

  • The code q I’m applying test is the top one, I ran the test with the phrase "Hello world" straight into the variable, and it was the same way

  • 1

    Test this in your code. <?php $Origin = "Hello World"; ? > <input type="text" placeholder="Origin" value="<? php echo $Origin; ?>"/>

2 answers

3


Your value=<?php echo $Origem; ?> must be value="<?php echo $Origem; ?>"

1

Kind of meaningless to type Olá mundo in a field that will only accept numbers, but I will publish my reply

From what I saw in the code, who doesn’t let you type more than 4 characters is the one maxlength="4"

The attribute maxlength specifies the maximum length of the value that can be inserted

So hello + a space add up to a length = 4

<a a class="arib">Origem: </a><input type="text" maxlength="4" placeholder="Origem" value="" name="origem" style="width:220px;"/>

Second comment from AP Eu havia digitado errado no exemplo acima, mas no meu código estava um 40, o que solucionou o problema foi a solução do amigo Wess acima, I don’t think the problem was the lack of quotation marks on the value, since value always has a value filled by php <?php echo $Origem; ?> To prove I put an example below that even without quotes works to the satisfaction.

<a a class="arib">Origem: </a><input type="text" maxlength="40" placeholder="Origem" value=12  name="origem" style="width:50px;"/>

  • I had typed wrong in the example above, but in my code was a 40, what fixed the problem was the solution of friend Wess above, but thank you for noticing this error in my question is already fixed :D

  • I had misread and put a wrong example in the question, corrected the question with the right field and with the right instructions, reaffirm that the answer of Wess worked very well, because in my code everything was right

Browser other questions tagged

You are not signed in. Login or sign up in order to post.