1

i have this code, but i can't understand why var_dump($jobs[0][0]) return Some Director, but when i do value='.$jobs[$i][0].' i simply get the first word, in this case only "Some". The question is why ? The same occurs in the others inputs.

thanks

<form method="post" id="customForm" action="">
    <?php
    for ($i = 0; $i < count($jobs); $i++) {
        $u = $i+1;
        echo '
        <div class ="empregadores" id="input_'.$u.'" style="margin-bottom: 10px;">
            <input placeholder="Cargo" name="myformdata[role][]" type="text" value='.$jobs[$i][0].' > 
            <input placeholder="Empregador" name="myformdata[company][]" type="text" value='.$jobs[$i][1].' >
            <input placeholder="Função" name="myformdata[role_function][]" type="text" value='.$jobs[$i][2].' >
        </div>';
    }

    ?>
    </form>

var_dump($jobs);

array
  0 => 
    array
      0 => string 'Some Director'
      1 => string 'some company' 
      2 => string 'some text' 

2 Answers 2

1

You have not enclosed the values in double quotes inside the value= attributes. Add opening and closing quotes, as in: value="'.$jobs[$i][0].'"

    echo '
    <div class ="empregadores" id="input_'.$u.'" style="margin-bottom: 10px;">
        <input placeholder="Cargo" name="myformdata[role][]" type="text" value="'.$jobs[$i][0].'" > 
        <input placeholder="Empregador" name="myformdata[company][]" type="text" value="'.$jobs[$i][1].'" >
        <input placeholder="Função" name="myformdata[role_function][]" type="text" value="'.$jobs[$i][2].'" >
    </div>';

Without the quotes, the HTML looks like value=Some director. The value ends at the first whitespace if not enclosed in quotes.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to wrap the HTML attribute in double-quotes. For example, change this:

... type="text" value='.$jobs[$i][0].' > 

to this:

... type="text" value="'.$jobs[$i][0].'" > 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.