0

I have address the 2nd street text box(2nd street line), but when I enter the address on both text boxes.

code for 1st street line

<input type="text" name="street[]"
    value="<?= $block->escapeHtmlAttr($block->getStreetLine(1)) ?>"
    title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?>"
    id="street_1"
    class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>"/>

code for other street lines

 <div class="nested">
      <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
       <?php for ($_i = 1, $_n = $this->helper(\Magento\Customer\Helper\Address::class)->getStreetLines(); $_i < $_n; $_i++): ?>
           <div class="field additional">
                 <label class="label" for="street_<?= /* @noEscape */ $_i + 1 ?>">
                  <span><?= $block->escapeHtml(__('Street Address %1', $_i + 1)) ?></span>
                        </label>
                        <div class="control">
                            <input type="text" name="street[]"
                                   value="<?= $block->escapeHtmlAttr($block->getStreetLine($_i + 1)) ?>"
                                   title="<?= $block->escapeHtmlAttr(__('Street Address %1', $_i + 1)) ?>"
                                   id="street_<?= /* @noEscape */ $_i + 1 ?>"
                                   class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>">
                        </div>
                    </div>
                <?php endfor; ?>
            </div>

I checked the address from street_1 and street_2 are saved as one in street column of the table customer_address_entity separated by a newline "\n"

When I print this <?= $block->escapeHtmlAttr($block->getStreetLine(1)) ?> in php echo but gives me empty result, but somwehow the street address is set in the textbox.

I need to get the street address and split it into for street_1 and street_2

enter image description here

I don't see any value set to value attribute in chrome inspect as per code. Then how value is getting populated. And how can I get that value and split to get the first line of street and 2nd line of the street address?

4
  • where did you get the street address? after placed order or? Commented Jun 12, 2019 at 8:35
  • @MSA its in customer address form. Magento_Customer/templates/address/edit.phtml
    – summu
    Commented Jun 12, 2019 at 8:36
  • Are you want to get street address values after placed order? Commented Jun 12, 2019 at 8:41
  • This has nothing to do with order placement. this is a customer is saving it addresses in my account section. which eventually saves it in customer_address_entity table
    – summu
    Commented Jun 12, 2019 at 8:43

1 Answer 1

0

I've checked over the magento logic

https://github.com/magento/magento2/blob/1f773294d446fdab61966ba4160c9427c5a7ce7e/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml#L56-L69

And something seems a bit odd with the numbering and how that's been written.

Try echoing out the following and see what comes out

<?= $block->escapeHtmlAttr($block->getStreetLine(0)) ?>
<?= $block->escapeHtmlAttr($block->getStreetLine(1)) ?>
<?= $block->escapeHtmlAttr($block->getStreetLine(2)) ?>
<?= $block->escapeHtmlAttr($block->getStreetLine(3)) ?>
<?= $block->escapeHtmlAttr($block->getStreetLine(4)) ?>

Could be the number isn't what you expect it to be.

3
  • I have pasted the exact same code, but its not working, it somehow shows the street_1 and street_2 both in the street_1 text box. and when I print <?= $block->escapeHtmlAttr($block->getStreetLine(0)) ?> it prints nothing, you can see my screenshot image also whats goofiness is going on, value attribute is empty but how the value is displayed and from where it is getting set.
    – summu
    Commented Jun 12, 2019 at 11:11
  • @summu what about if you echo 1, 2, 3 4 values. Still all blank? The only other thing I can think is you've got values in local storage. They're not in php. Try different browser? Commented Jun 12, 2019 at 12:06
  • yes all gives blank, I tried by clearing all local storage values and incognito mode as well.
    – summu
    Commented Jun 13, 2019 at 9:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.