Psygno
Psygno

Reputation: 261

set_value() as value for associative array

In CodeIgniter 3 I have a classic form setting with:

$cssaltezza = array('name' => 'altezza',
                   'id' => 'altezza',
                   'class' => 'form-control',
                   'placeholder' => 'Altezza'
                  );
<?php echo validation_errors(); ?> 
<?php echo form_open('clienti/misure_validation'); ?> 
 <?php echo form_input($cssaltezza); ?>
  <?php echo form_submit($csssubmit); ?>
<?php echo form_close(); ?>

I'd like to add a set_value(); rule to repopulating forms after an error. Docs explain an example where I use html tag . for example:

<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" />

It's not my case, so if I menage the array with settings like this:

$cssaltezza = array('name' => 'altezza',
                   'id' => 'altezza',
                   'class' => 'form-control',
                   'value' => '<?php echo set_value("altezza"); ?>',
                   'placeholder' => 'Altezza'
                  );

I have as result that in the text box it's written

php echo set_value("altezza");

as text. If I change the quotes I have a PHP error. If I use:

<?php echo set_value("altezza"); ?>
 <?php echo set_value("altezza"); ?>

It works but the data is output outside the textbox...I'm stuck in this, can someone help me to understand where I'm wrong? I'm I doing something that codeigniter can't?

Upvotes: 0

Views: 507

Answers (2)

dhruv jadia
dhruv jadia

Reputation: 1680

change from

 $cssaltezza = array('name' => 'altezza',
                       'id' => 'altezza',
                       'class' => 'form-control',
                       'value' => '<?php echo set_value("altezza"); ?>',
                       'placeholder' => 'Altezza'
                      );

to

$cssaltezza = array('name' => 'altezza',
                   'id' => 'altezza',
                   'class' => 'form-control',
                   'value' => set_value("altezza"),
                   'placeholder' => 'Altezza'
                  );

Upvotes: 1

safin chacko
safin chacko

Reputation: 1390

try

<input type="text" value="<?php echo set_value('altezza'); ?>" >

Upvotes: 0

Related Questions