This topic is locked

Bit lost need help

9/17/2012 4:59:34 PM
PHPRunner General questions
W
wildwally author

Ok - PHPRunner has spoiled me and now I've worked myself into a corner. I'm in need of a solution that can query the datbase and for each result or row add three fields for the user to add values to then submit it back to the database. Surprisingly I was able to write my own code to query and add the text fields but I don't know how to get the submit button to post the all the data back with either an update or an insert as an array.

So is there a way to do this with PHPR by itself?
Here is what I'm doing with the results to add the textbox:


echo '<table width="300" border="1" cellspacing="1" cellpadding="1" bgcolor="FFFFFF">';

while($row=db_fetch_array($rs))

{

?>

<tr align='center'>

<td></td>

<td></td>

<td><? echo $row["Code"];?></td>

<td><? echo $row["Function"];?></td>

<td align='center'><input size='3' maxlength='3' type='text' name='REG[<? echo $i;?>]'/></td>

<td align='center'><input size='3' maxlength='3' type='text' name='PT[<? echo $i;?>]'/></td>

<td align='center'><input size='3' maxlength='3' type='text' name='OT[<? echo $i;?>]'/></td>

</tr>

<?

$i++;

}


And this works so far. Now what do i do to get button to run a query? (I can handle the query piece)
Thanks in advance.

W
wildwally author 9/18/2012



Check this article: http://xlinesoft.com...eld_to_form.htm


Cristian thanks for the reply and I had thought through things last night and figured out a work around from doing a completly custom page. I found this that you supplied, but I still need some help with it. I'm now using that in a PHP Snippet and it loads on the sheet great. However, the fields if I done it right have [#] (keys) to allow for multiple auto generation. Using the javascript how would I get it to account for dynamic approach?

C
cgphp 9/18/2012

If you are using a snippet, add a custom button.
In the "Client before" event get the values of the inputs and pass that values to the Server events.

In the Server event add the update/insert queries.

W
wildwally author 9/18/2012



If you are using a snippet, add a custom button.
In the "Client before" event get the values of the inputs and pass that values to the Server events.

In the Server event add the update/insert queries.


Getting the values is where I'm having my troubles.
if my query results pulls back three rows I'm creating three input boxes (example)
input#REG[0]
input#REG[1]
input#REG[2]
If more results then it would keep going.
How do I get the javascript to loop through the custom generated fields in order to pass back to server?

Sergey Kornilov admin 9/18/2012

You can do that using jQuery. val() function will read the value of any input control you specify:

http://api.jquery.com/val/

W
wildwally author 9/19/2012

I was able to get this to work, but is there a way to tell it to only look at fields with a specific name or id?

this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){
var val = '';
$("input").each(function() {

if(val != '')

{

val = val + ",'" + $(this).val() + "'";

}else{

val = "'" + $(this).val() + "'";

}

//params["string"] = val;



});
formObj.baseParams['TIME_X'] = val;
});


Sergey Kornilov admin 9/19/2012

Sure, check jQuery docs. Selecting by id is a bit easier:

http://api.jquery.com/id-selector/