This topic is locked
[SOLVED]

 custom dropdown on import page -> how to pass select

6/15/2011 8:03:11 AM
PHPRunner General questions
M
mickna author

Hi,
I need to have a dropdown box at the import page to get import work properly with my structure.

How can I pass the value from this dropdown to insert it in my table?
at the import page I added a php snippet to generate the dropdown and it works fine:

global $strTableName, $conn;

$value = "<select name=\"ColName\" id=\"ColName\">";

$str = "SELECT userColName FROM col_usercollections WHERE `userName` = '".$_SESSION["UserID"]."' AND `userColLayout` = '".$strTableName."'";

$rs = db_query($str,$conn);
while ($data = db_fetch_array($rs))

$value.="<option value=\"".$data["userColName"]."\">".$data["userColName"]."</option>";

$value.="</select>";

echo $value;


I thought I can pass the value somehow via "document.getElementById('ColName').value".
I need to add this value additional to all entry from the imported cvs to my table, but how can I catch it at "Import page - Before Insert Record" to use $values["xyz"] = ??
thanks,

mickna

admin 6/15/2011

You should be able to access it as $_POST['ColName']

M
mickna author 6/15/2011

Hi Sergey,
I tried this (to be honest, I tried POST, REQUEST and GET lol) and no I can't get it via $_POST['ColName'].

The corresponding field is just "NULL".

If I declare a normal string like "TEST" it is written to the database. So my syntax should be right.
Side note: I insert this into Before Insert Record (should be the right place...)

$values["fieldname"] = $_POST['ColName'];


Any ideas?

Thanks,

mickna

C
cgphp 6/16/2011



Hi Sergey,
I tried this (to be honest, I tried POST, REQUEST and GET lol) and no I can't get it via $_POST['ColName'].

The corresponding field is just "NULL".

If I declare a normal string like "TEST" it is written to the database. So my syntax should be right.
Side note: I insert this into Before Insert Record (should be the right place...)

$values["fieldname"] = $_POST['ColName'];


Any ideas?

Thanks,

mickna


http://xlinesoft.com/phprunner/docs/add_custom_field_to_form.htm

M
mickna author 6/16/2011

Thank you cgphp,
However you missed that I am talking about import.

Under Import there is no JavaScript OnLoad event.

I saw this also.
mickna

C
cgphp 6/16/2011



Thank you cgphp,
However you missed that I am talking about import.

Under Import there is no JavaScript OnLoad event.

I saw this also.
mickna


Sorry mickna, you are right.

admin 6/16/2011

Here is how this can be done.

  1. Add a new field to the form. You have already done that. Field name and id are both ColName.
  2. Remove the standard 'Import' button and add your own custom button.

    In ClientBefore event use the following code:

var path = $("#file_ImportFileName" + pageObj.id).val();

if (!path) {

return false;

}

var wpos = path.lastIndexOf("\\");

var upos = path.lastIndexOf("/");

var pos = wpos;

if (upos > wpos) {

pos = upos;

}

baseParams = {a: "added", id: pageObj.pageId};

baseParams["value_ImportFileName" + pageObj.id] = path.substr(pos + 1);

baseParams["type_ImportFileName" + pageObj.id] = "upload2";

var val = $("#ColName").val();

baseParams['ColName'] = val;
var form = new Runner.form.BasicForm({submitUrl: pageObj.submitUrl, standardSubmit: true, isFileUpload: true, method: "POST", baseParams: baseParams, id: pageObj.pageId, addElems: [$("#file_ImportFileName" + pageObj.id)]});

form.submit();


3. Now you can use $_POST['ColName'] in any server side event.

M
mickna author 6/17/2011

Sergey, this is PERFECT!!!

Even if this code is pure magic for me *lol
One more time: Thank you for the great support.