Welcome Guest, Not a member yet? Register   Sign In
displaying data in a form field
#1

[eluser]elmne[/eluser]
I want codecharge to display output in a form using values that come from a database.

So the form field is populated using a database value

Code:
<input type="text" name="customer_type_id" value"<?php echo $row->customer_type ?>" />

and also so that when a mistake is done and the form is reloaded after validate, it shows the value that was input i believe using the set_value function below

Code:
<?php echo set_value('customer_type'); ?>

How do i achieve the ability to display database output within a form field and also to repopulate that same field upon submission, should validation trigger the form to be reloaded?
#2

[eluser]bretticus[/eluser]
From the manual (emphasis added.)

Quote:set_value()

Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function. The second (optional) parameter allows you to set a default value for the form. Example:
<input type="text" name="quantity" value="<?php echo set_value('quantity', '0'); ?>" size="50" />

The above form will show "0" when loaded for the first time.

Set the default value from the database. When the function detects that the form has been submitted, the last value will be repopulated (not the default value.) The form must be submitted to itself (form url is the action parameter of form tag.)
#3

[eluser]elmne[/eluser]
Thanks,

How then do i get the default value in a dropdown box to be displayed?

Is this correct?

Code:
<select name="select"   value="&lt;?php echo set_value('customer_type',"$row->customer_type"); ?&gt;" >
       <option>*************</option>
       <option value="active">Active</option>
       <option value="inactive">Inactive</option>
</select>

The value in the database table may be NULL.

So the set value needs to either set the default;

- active
- inactive
- NULL (empty)

How do i set the default drop down value
and if it's NULL, how do i reflect that in the drop down by not having anything selected/set ?




Theme © iAndrew 2016 - Forum software by © MyBB