0
votes

I am trying to make a placeholder for forms in concrete5 using a the tablelessforms addon.

So far I have enabled the form to produce placeholders for inputs using the below code. However, the textarea while displaying, the function str_replace does not replace and add my placeholder.

Here is the code below and a link to the site : http://79.170.44.138/holidayletmidwales.co.uk/newsite/

<div class="fields">

    <?php  foreach ($questions as $question): ?>
        <div class="field field-<?php  echo $question['type']; ?>">
            <?php if ($question['textarea']) {   
                      $question['textarea'] = str_replace('rows="3"', 'rows="3" placeholder="'.$question['question'].'"', $question['textarea']); 
                    echo $question['textarea'];         
                    } else { 
                       $question['input'] = str_replace('value=""', 'value="" placeholder="'.$question['question'].'"', $question['input']);
                      echo $question['input'];          
                 } ?>       
            </div>  
    <?php  endforeach; ?>

</div><!-- .fields -->

Any help would be greatly appreciated.

1
Your code would be a lot easier to read, if you dont use <?php.. ?> around every line in a contiguous block of PHP code - RiggsFolly

1 Answers

1
votes

The find and replace isn't working as you're searching for rows="3" when the markup has rows="5". A better option, rather than searching for an attribute which could change, would be to find the beginning of the tag, e.g. str_replace ('<input', '<input placeholder="foo"', $html) or, if possible, to extend the class generating the tags to handle placeholders as you require.