michal
Založený: 17.06.2003
Príspevky: 537
Bydlisko: Slovakia
Zaslal: 2003-08-25 23:33
Návrat hore
Odpovedať s citátom
|
meaning that i can control submited strings whether they follow the rules, other than non empty as current javascript or default control in database.
the submited strings could go through an "input function" which would control the strings and stop the insert process if the strings are not correct.
example: currency input. some users tend to input '10 236,5 Sk' instead of '10236.5' thinking that it looks nicer. a simple strtr solves it. a currency limit can be added for each user.
other desireble features:
mergin cells, example having date and time in separate displayed columns and having datetime in database.
dividing cells, inseriting 'first last_name' and have 2 cols in databaze displayed with 'sql' option.
is such implementation of input function desired by other users ? should work on patch ?
also concerns bug 121 http://opensource.platon.sk/projects/bug_view_advanced_page.php?f_bug_id=121
|
bernie95
Založený: 03.09.2003
Príspevky: 10
Zaslal: 2003-09-03 12:08
Návrat hore
Odpovedať s citátom
|
Hi,
I'm also interested in input control, mainly in the form of field combination or split; the main case that I think would have to be handle is one input field containing, for example, full name and two database fields (probably hidden input fields) that get (after possible user confirmation) the split last and first names, with possibly name prefixes and suffixes, so that typing in Dr John X. Doe III will get "Dr" in the prefix, "John X." in the first name, "Doe" in the last name and "III" in the suffix.
I think this should be not too difficult to implement with some JavaScript triggered by user modification of the fullname input field and setting hidden input fields. The problem is having phpMyEdit knowing that the fullname field is in fact NOT an database field, but should be displayed by concatenating data in other fields, like this is done for displaying the description part of select dropdown lists (and associated field) fetched from another table.
Maybe a configuration option like
| Kód: |
$opts['fdd']['fullname']['compound'] = array(
'columns' => array('firstname', 'lastname'),
'divs' => array('/', '/'),
'split' => array('\(.*\) *\([AZa-z]+\)'),
'orderby' => "Nom, Prenom"
); |
could be used to, as a first step, generate the JavaScript code using the regexp given in 'split' (I'm not sure of the syntax and certainly a more advanced solution could be devised) to split the input, while phpMyEdit will display the two database columns as one and generate the needed hidden inputs.
I think it's better to split in JavaScript as then the JavaScript code cand act immediately when the data is typed in and update the display of "John Doe" in, e.g. "John /Doe/" to emphasize how the split was done.
|
michal
Založený: 17.06.2003
Príspevky: 537
Bydlisko: Slovakia
Zaslal: 2003-09-17 22:16
Návrat hore
Odpovedať s citátom
|
i have something like this implemented in my alpha demo version. however it is done purely by php, java is a mystery for me :)
my point was to ask, whether there is need for a user defined input function (in php, as a part of the insert script). however, the incoming and outgoing variables should be defined correctly and broadly enough.
my current needs are:
ability to insert into more columns with data from one
to insert into one column with data from more
to stop the insert process if needed (and post a error message to the user, so that he could change the values).
i don't know what my future needs will be, that's why i post it here, to kill more flies with one hit
|
michal
Založený: 17.06.2003
Príspevky: 537
Bydlisko: Slovakia
Zaslal: 2003-11-11 23:20
Návrat hore
Odpovedať s citátom
|
for each column you can define your own input function. like
'input_function' => 'myfunction($row,$value)'
usage is similar as before insert triggers (well it's the same :), difference is that you do not have to have many small triggers. drawback is that it's eval-ed.
other main change is that the insert query is construced completely _after_ the before trigger from name => value array. so you cat easily change the insert values as needed.
so here is the patch:
somewhere
| Kód: |
function col_has_input_function($k) { return isset($this->fdd[$k]['input_function']); }
@@ -2230,35 +2231,50 @@
function do_add_record() /* {{{ */
{
// Preparing query
- $query = '';
$key_col_val = '';
- for ($k = 0; $k < $this->num_fds; $k++) {
- if ($this->processed($k)) {
- }
- }
- $vals_quoted = array();
$newvals = array();
- for ($k = 0; $k < $this->num_fds; $k++) {
+ for ($k = 0; $k < $this->num_fds; $k++) { // inserting cgi values into row[]
if ($this->processed($k)) {
- $fd = $this->fds[$k];
if ($this->readonly($k)) {
$fn = (string) @$this->fdd[$k]['default'];
} else {
$fn = $this->get_cgi_var($this->fds[$k]);
}
+ $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;
if ($fd == $this->key) {
$key_col_val = addslashes($fn);
}
- if ($query == '') {
- $query = 'INSERT INTO '.$this->tb.' ('.$fd; // )
+ }
+ }
+ $row = $newvals;
+ $this->input_error = ''; // you can insert error message here
+ $row_current = array(); // array to be later inserted in form colname => value
+ for ($k = 0; $k < $this->num_fds; $k++) { // applying input_functions and creating row_current
+ if ($this->processed($k)) {
+ $fd = $this->fds[$k]; $name = $fd;
+ if ($this->col_has_input_function($k)) {
+ $value = $row[$fd];
+ $work = eval ("return ".$this->fdd[$k]['input_function'].";");
+ if ($this->input_error != '') {
+ echo $this->input_error;
+ return false;
+ }
+ if (is_array($work)) { echo ' array ';
+ foreach ( $work as $col_name => $value ) {
+ if ($value != NULL) {
+ $row_current[$col_name] = $value;
+ }
+ }
+ } else {
+ if ($work != NULL ) $row_current[$fd] = $work;
+ }
} else {
- $query .= ','.$fd;
+ if ($row[$fd] != NULL ) $row_current[$fd] = $row[$fd]; // MI added condition, important
+ echo $name."->".$row[$name];
}
- $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;
- $vals_quoted[$k] = addslashes($newvals[$this->fds[$k]]);
- $vals_quoted[$k] = "'".$vals_quoted[$k]."'";
}
}
+ $newvals = $row_current; // now newvals has the values to be inserted, for compatibility
// Creating array of changed keys ($changed)
$changed = array_keys($newvals);
// Before trigger
@@ -2269,8 +2285,24 @@
}
}
// Real query (no additional query in this method)
- $query .= ') VALUES ('.join(',',$vals_quoted).')'; // )
+ $query = '';
+ foreach ($row_current as $col_name => $value ){
+ echo $col_name.'=>'.$value.'<br>';
+ if($value == NULL ) continue;
+ $value = "'".addslashes($value)."'";
+ if ($query == '') {
+ $query = 'INSERT INTO '.$this->tb.' (`'.$col_name.'`';
+ $query2 = ') VALUES ('.$value;
+ } else {
+ $query .= ', `'.$col_name.'`';
+ $query2 .= ', '.$value;
+ }
+ }
+ $query .= $query2; $query .= ')'; echo '<br>'.$query;
+ //$query .= ') VALUES ('.join(',',$vals_quoted).')'; // )
$res = $this->myquery($query, __LINE__);
+
+
$this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record added'];
if (! $res) {
return false;
|
|
|
Odoslať novú tému
Odpovedať na tému
|
|