Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Fill fields with some value if I'm editing but also re-populating the form on submit
#1

[eluser]ReyPM[/eluser]
Hi every, I'm building a CRUD for a table (not using any external tool) but I'm confused here while editing a record. As said here at docs Form Validation for re-populating the form I must use the set_value() function but what if I'm editing a record where value is populated from returned data by a previous query? How to handle the re-populating in this case? Any help or advice?
#2

[eluser]CroNiX[/eluser]
Code:
set_value($field, $default);

$default will be used when the page first loads.
$field value will be used if the form was submitted.

It's (2nd paramter of set_value()) not explained in the Form Validation section of the User Guide, but it is in the Form Helper section.
#3

[eluser]ReyPM[/eluser]
[quote author="CroNiX" date="1352150787"]
Code:
set_value($field, $default);

$default will be used when the page first loads.
$field value will be used if the form was submitted.[/quote]

So if I'm right $default should be the value come from DB and $field should be the value for the re-populating? Also could you please write a small example in how logic should be from the controller? I'm lost here by the way thanks
#4

[eluser]CroNiX[/eluser]
Yes.
controller
Code:
//get user data value for field1
$data['user_data'] = array('field1' => 'one'); //normally coming from db

//view
Code:
<input type="text" name="field1" value="<?php echo set_value('field1', $user_data['field1']; ?>" />

When the page/form first loads, it will have "one" for the value in the "field1" form field.
Once submitted, it will be whatever value was in the "field1" field.
#5

[eluser]ReyPM[/eluser]
Ok so there is not need for this code:
Code:
value="<?php echo!isset($article) ? set_value('number_pub', $article->NUMBER) : set_value('number_pub'); ?>"
#6

[eluser]CroNiX[/eluser]
Nope, just 1 set_value() like I showed.
#7

[eluser]ReyPM[/eluser]
Ok, many thanks CroNiX
#8

[eluser]ReyPM[/eluser]
Ahh one last question, what about SELECT, CHECKBOX and OPTION BUTTON? How to deal with those?
#9

[eluser]CroNiX[/eluser]
Those have their own functions since they differ. See the bottom of the Form Helper section of the user guide.
#10

[eluser]ReyPM[/eluser]
Ok, I'll check also see this case (maybe I'm wrong)
Code:
$revista = array();
<?php echo set_value('id_revista', $revista->REVISTA); ?>

When $revista is empty I get this error:
Quote:A PHP Error was encountered
Severity: NoticeMessage: Trying to get property of non-objectFilename: articles/articles_form.php
Line Number: 37
Where line Number 37 is set_value ....
What I'm doing wrong here?




Theme © iAndrew 2016 - Forum software by © MyBB