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
#11

[eluser]CroNiX[/eluser]
Well, you created $revista as and empty array, but trying to access it as an object in set_value(). There also is no "REVISTA" key (or property) in your $revista array.
#12

[eluser]ReyPM[/eluser]
[quote author="CroNiX" date="1352152753"]Well, you created $revista as and empty array, but trying to access it as an object in set_value(). There also is no "REVISTA" key (or property) in your $revista array.[/quote]
Then maybe in this particular case my approach:
Code:
value="<?php echo!isset($revistar) && !empty($revista) ? set_value('id_revista', $revista->REVISTA) : set_value('id_revista'); ?>"
is right or still wrong?
#13

[eluser]CroNiX[/eluser]
That depends entirely on you and what you are doing.

When editing, I send all current data (form fields retrieved from db) from the controller, which is all used in the 2nd parameter of set_value() or whatever. So all fields would have a default value and I'd never run into that problem. You're running into it because you are not using real data and you're doing it wrong (accessing an array as if it was an object...won't work, neither will trying to access a key/property that doesn't exist because you didn't create it for your test)

When creating, obviously these values don't exist and you either don't use the 2nd parameter, or create an object/array with the same key fields with no values and the same form will work for both creating and editing. There are a lot of ways to go here, but it depends on your situation and what you're doing.
#14

[eluser]ReyPM[/eluser]
Ok, as you said I retrieve fields from DB. Exists two main tables will call table1 and table2, table1 has a id_table2 and this is how they are related. In some cases this fields have a 0 value which is a real problem because no AUTO INCREMENT value is 0 and then table2 start in 1. This is a previous problem from the DB not mine so when this value is 0 not array is filled and there is when the problem appears so I don't know which is the best solution. What do you think about that? Also I'll take into account all the suggestions you said before and once again thanks for your support




Theme © iAndrew 2016 - Forum software by © MyBB