Page 1 of 1

Automagically filling out contact form fields

Posted: Tue Dec 22, 2009 1:27 pm
by yellowled
Okay, this may sound a tad insane, and yes, I know it's not a typical blog feature. It's also no biggie if it simply isn't possible, but I thought I'd ask anyway :)

A client's site uses blog entries for job openings, i.e. every job opening is a blog post. At the end of every blog post is a link to a dynamic contact for for online applications. This dynamic form has a field holding the job description the user wants to apply for, which is also used as the title of the related blog post.

You guys still with me? Great.

So I was wondering whether it would be possible (using some kind of voodoo magic) to automagically fill out the form field "job description user is applying for" with the title of the blog post from which the form is accessed, if that makes any sense at all ..? (If it doesn't, I'll have to post it to the German forum and Garvin will have to solve it on his own :D)

Again, no biggie if there's no way, I just can't say whether there is a way or not.

YL

Re: Automagically filling out contact form fields

Posted: Tue Dec 22, 2009 3:54 pm
by perlnerd
I am a relative n00b when it comes to serendipity and smarty templates but have been programming php for many years. Here's what I'd suggest you look at.

In your template file entries.tpl you can use the smarty variables to access various parts of the blog post. I'd think you could add something like this to the end of the blog post and leverage the smarty variable {$entry.title}:

Code: Select all

<a href="http://yourdomain.com/applyforthisjob.php?jobTitile={$entry.title}">Apply for this Job</a>
You might need to URL encode {$entry.title}

Code: Select all

<a href="http://yourdomain.com/applyforthisjob.php?jobTitile={$entry.title|escape:'url'}">Apply for this Job</a>
Then you can grab the entry title from the query string and insert it into your form on the other end.

Clint

Re: Automagically filling out contact form fields

Posted: Tue Dec 22, 2009 5:09 pm
by yellowled
perlnerd wrote:You might need to URL encode {$entry.title}

Code: Select all

<a href="http://yourdomain.com/applyforthisjob.php?jobTitile={$entry.title|escape:'url'}">Apply for this Job</a>
Does this also work if the form addressed is a HTML page? Like this?

Code: Select all

<a href="/serendipity/apply.html?fieldname={$entry.title|escape:'url'}">...</a>
YL

Re: Automagically filling out contact form fields

Posted: Tue Dec 22, 2009 6:01 pm
by perlnerd
You'd need a way of getting $_GET['fieldname'] into your contact form. You'll have to do some php coding.