• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pre-populate form data

#1
[eluser]Bionicjoe[/eluser]
This is a hack & slash copy/paste form I'm trying to use.
In option 1 all the fields are pre-populated with data from the record to be edited. That's good, but I have no way to format the form the way I need. Not every field can be a simple input field.

I need a form that looks like option 2, but I'm having trouble getting the fields to populate with data from the record.

Option 1
Code:
<?php
echo form_open('update');

echo form_hidden('outageid', $row[0]->outageid);

// an array of the fields in the outage table
$field_array = array('ticketnumber',    'servicename', 'summary',    'sitename', 'starttime', 'endtime');
foreach($field_array as $field_name)
{
  echo '<p>' . $field_name;
  echo form_input($field_name, $row[0]->$field_name) . '</p>' . "\r";
}

// not setting the value attribute omits the submit from the $_POST array
echo form_submit('', 'Update');

Option 2
Code:
$this->load->helper('array');
echo form_open('update');

echo form_hidden('outageid', $row[0]->outageid);

// an array of the fields in the outage table
$field_array = array('ticketnumber',    'servicename', 'summary',    'sitename', 'starttime', 'endtime');

                <table>
                    <tr><td>Number</td><td>&lt;input type="text" name="ticketnumber" value="&lt;?php echo element('ticketnumber', $field_array)?&gt;"&gt;&lt;/td><tr>
                    <tr><td>Affected Services</td><td>&lt;?php echo form_dropdown('servicename', $serviceoptions); ?&gt;</td><tr>
                    <tr><td>Summary</td><td>&lt;input type="text" name="summary"&gt;&lt;/td><tr>
                    <tr><td>Location</td><td>&lt;?php echo form_multiselect('sitename', $siteoptions); ?&gt;</td><tr>
                    <tr><td>Start</td><td>&lt;input type="text" name="starttime"&gt;&lt;/td><tr>
                    <tr><td>End</td><td>&lt;input type="text" name="endtime"&gt;&lt;/td><tr>
                    <tr><td></td><td>&lt;input type="submit" value="Submit"&gt;&lt;/td><tr>
                </table>
*/
echo form_close();

#2
[eluser]Bionicjoe[/eluser]
Getting closer.
I edited the following line, but now I get only the first letter of data.
WTF?

Code:
<tr><td>Number</td><td>&lt;input type="text" name="ticketnumber" value="&lt;?php echo element('ticketnumber', $row[0]-&gt;ticketnumber);?&gt;"></td><tr>

#3
[eluser]mah0001[/eluser]
Try this:

Code:
<tr>
<td>Number</td>
<td>&lt;input type="text" name="ticketnumber" value="&lt;?php echo $row[0]-&gt;ticketnumber;?&gt;"></td>
<tr>

#4
[eluser]Bionicjoe[/eluser]
D'OH!!

Ever make something too hard by thinking too much?

Thanks, mah0001

#5
[eluser]mattpointblank[/eluser]
Does $row->ticketnumber give you what you want?

#6
[eluser]eoinmcg[/eluser]
html police here!

looks like you haven't closed your <tr>. tut, tut!

Quote:
Code:
<tr>
<td>Number</td>
<td>&lt;input type="text" name="ticketnumber" value="&lt;?php echo $row[0]-&gt;ticketnumber;?&gt;"></td>
<tr>

#7
[eluser]Bionicjoe[/eluser]
[quote author="mattpointblank" date="1267046987"]Does $row->ticketnumber give you what you want?[/quote]

Code:
$row[0]->ticketnumber
Does what I need.

And thanks, I've fixed my html. Tongue


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.