简体   繁体   中英

How do I update the value attribute of a form input with data from variable?

How do I update the value attribute of a form input with data from variable?

Now when the form shows it does not take the data from the variable istead it just autofills: {$title}

I tried curly braces and different quatation marks to solve this. There is something I am overlooking.

for ($i = 0; $i < sizeof($list_array); $i++) {
    $title = $list_array[$i]->find('h3', 0)->plaintext;
    $price = $list_array[$i]->find('span[class="hz-Listing-price hz-text-price-label"]', 0);

    $string = $price;
    $clean_string = preg_replace('/[^\d]+/', '', $string);
    
    $integer = intval($clean_string);
    $result = $integer / 100;
    
    echo "<li>";

    if ($result < 10000 && $result > 2000) {
        echo "<p><span style=\"color: green\">$title</span></p>";
        echo "<p><span style=\"color: green\">$result</span></p>";
        echo
        '<div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <h4>
                                Add Contacts
                                <a href ="index.php" class=" btn btn-danger float-end" > Back</a>
                            </h4>
                        </div>
                        <div class="card-body">

                        <form action="code.php" method="POST">

                        <div class="form-group mb-3">
                            <label for="">First Name</label>
                            <input name="first_name" <sup>value="{$title}"</sup> class="form-control">
                        </div>
                        <div class="form-group mb-3">
                            <label for="">Phone Number</label>
                            <input name="phone" value="$result" class="form-control">
                        </div>
                        <div class="form-group mb-3">
                            <label for="">Note</label>
                            <input type="text" name="note" class="form-control">
                        <div class="form-group mb-3">
                            <button type="submit" name="save_contact" class="btn btn-primary">Save contact</button>
                            
                        </div>
                        </form>

                        </div>
                    </div>
                </div>
            </div>
        </div>';
    } else {
      //echo "<p>$title</p>";
      //echo "<p>$result</p>";
    }
}

I needed to break into the echo.

I did this by

input type="text" name="first_name" value='. $title.' class="form-control">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM