/    Sign up×
Community /Pin to ProfileBookmark

Passing paramaters to PHP select form

I have a selection form and I want the input type to be a button that calls a PHP function. I need the PHP function to know what the selection value is for the form and I also need to have the variable for the database connection that I opened previously.

I think that the database connection variable should be sent as a parameter, and the selection value should probably not be sent as a param but be retrievable from within the PHP function. I can’t figure out how to do either of these things though, from online examples.

EDIT – Actually, it doesn’t even seem to be calling my function even without arguments.

<input type=”button” name=”ddd” value=”ddssd” onclick=”test()”>

only seems to work if test() is a javascript function…is there no way to call a php function this way? Is it absolutely necessary to create a separate php file and then use the action=”ddsds.php”?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 06.2006 — One option would be to make it a submit button, with a name different than the "regular" submit button. Clicking it would still call the same form-handler that you are pointing to in the action attribute of the form tag, but you can put some logic in that script to do different processing depending on which button was clicked.

HTML
<i>
</i>&lt;form action='handler.php' method='post'&gt;
&lt;!-- various form elements here, then... --&gt;
&lt;input type='submit' name='ddd' value='ddssd'&gt;
&lt;input type='submit' name='xxx' value='submit'&gt;
&lt;/form&gt;

handler.php:
[code=php]
if(isset($_POST['ddd']))
{
// do whatever needs to be done when the 'ddd' button is clicked
}
elseif(isset($_POST['xxx']))
{
// do whatever needs to be done when the 'xxx' button is clicked
}
[/code]
Copy linkTweet thisAlerts:
@stuh505authorJul 06.2006 — I don't think that's what I need. I didn't explain very well, let me try again--

When they click the form button, this calls a javascript function

which initiates a PHP function on the server. That PHP function needs

to know what the value of the selection index is. I don't even know how to acquire this value let alone pass it. I tried saying method = get or post but

wasn't sure how to make that work, if its possible. So that's 1 problem.

It also needs the $con object. $con is declared outside of a function so I would expect it to be 'global' yet it seems to be out of scope by the time php_update_map_orgs() gets it, so that's the second problem.

There is one third and final problem. The PHP script on the server needs to call a local javascript function AND pass variables from PHP to that javascript function (draw_map_org). I don't know how to pass a PHP variable to a javascript function, so that's the final problem.


I have this in my body:

<form name="frm_sel_fos" method="get">

<select name="sel_fos">

<?php

db_create_fos_ddl($con,0,"[SELECT FIELD OF STUDY]");

?>

</select>

<input type="button" name="btn_sel_fos" value="Update Map" onclick="update_map_orgs()">
</form>

<div id="map" style="WIDTH: 500px; HEIGHT: 300px"></div>


===========

The above function calls the below javascript function which resides in the head.

===========

function update_map_orgs()
{
document.getElementById("msg").appendChild(document.createTextNode("Updating map..."));

<?php php_update_map_orgs(); ?>
}


=========

Now here is the php function:

function php_update_map_orgs(){

$sql = "SELECT DISTINCT org.organization_name, org.organization_url, org.organization_phone, org.nsf_org_code FROM acct.organizations org, acct.people p, acct.accounts_access acacc, acct.requests req WHERE req.primary_fos_id = "$fos" AND acacc.account_id = req.account_id AND p.person_id = acacc.person_id AND org.organization_id = p.organization_id;";

$rs = pg_exec($con,$sql);
$nrows = pg_numrows($rs);

echo $nrows;

for($i=0; $i<$nrows; $i++){
$row = pg_fetch_row($rs,$i);
$org_name = $row[0];
$org_url = $row[1];
$org_phone = $row[2];
$org_nsf_code = $row[3];

<script language=javascript>draw_map_org($org_name, $org_url, $org_phone, $org_nsf_code)</script>;
}

}

================
Copy linkTweet thisAlerts:
@NogDogJul 06.2006 — Possibly an AJAX implementation of JavaScript could help you out, but you'll have to get one of the JS/AJAX experts to help you with that.
×

Success!

Help @stuh505 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...