views:

86

answers:

5

I need to be able to print text into a form field from an <'a'> link.

Basically I have a list of job postings on one page, and an 'apply' link for each one. What then will happen is it'll bring up a form with the "Job Chosen" field already filled out with the "Job Title" from the previous page.

Something like

<a href="applyform.php?submitted[job_chosen]=job_title">Apply For Position</a>

I know that that is not right at all, just for explanation reasons.

A: 

You can do so using the query string

<a href="applyform.php?job={job title}">Apply For Position</a>

Then in your php page simply pull the "job" query string key and fill the contents of the field the values.

 <?php
  //get variable
  $d = $_REQUEST['VariableName'];
  //fill textbox
  print('<input type="text" name="job_title" value="' . $d . '" />');
jon3laze
A: 

You can do this in JavaScript, though I wouldn't. From another page:

function $_GET(q,s) {
    s = (s) ? s : window.location.search;
    var re = new RegExp('&amp;'+q+'=([^&amp;]*)','i');
    return (s=s.replace(/^\?/,'&amp;').match(re)) ?s=s[1] :s='';
}

document.getElementById("JobTitle").value = $_GET("job_chosen"); // Assuming "JobTitle" is an input element

This will get the value of job_chosen from a URL like: http://www.example.com/apply.html?submitted=1&amp;job_chosen=Software%20Developer

palswim
A: 

If it's only one thing you want added, you can just add it to the URL:

path/to/form/[nid]

I'm guessing that jobs are nodes, so you can just send along the node id. You can use that the title of the node.

You could also just send the title along, but the problem with that is that the url doesn't handle special characters very well, and it could quickly become a pain.

All you need to do in your form, it to get the nid, using arg(), and query the datebase for the node title, which is in the node table.

You can use the #default_value to prefill the form with the node title.

googletorp
+3  A: 

Here comes the there-is-a-module-for-that answer :D

The first 2 modules are more mature:

http://drupal.org/project/nodereference_url

http://drupal.org/project/prepopulate

http://drupal.org/project/urlfill

corbacho
Using prepopulate worked great!! I love it when there are modules :)
Erik
A: 

Nice, didn't knew http://drupal.org/project/prepopulate module.

Usage is very simple:

http://www.example.com/node/add/blog?edit[title]=this is the title

But it depends if your jobapply.php is custom php or directly involved with drupal.

If its just custom PHP the solution below is working. If its a drupal form, you can use the above module.

It really depends on what you need in this case.

LionsAd