Page 1 of 3
CP form: dynamic subject possible?
Posted: Thu 17. Jan 2008, 19:44
by update
Hi, today I ran into a little problem:
I have a form with a pulldown select box named {chooseme}. You can select just one from two or three item.
Now when I choose this {chooseme} for the subject line of the form template it replaces the subject with the first item of the list no matter which item I choose. Has anybody some hint how to get the chosen item into the "subject" line of the sent email?
Any hint is appreciated

Re: CP form: dynamic subject possible?
Posted: Thu 17. Jan 2008, 21:56
by update
Now I've tried it with almost all possible settings, searched the forum...
Only thing to find is an RT for automatic article title for the subject field, cool btw.
But that's not exactly what I'm looking for

- I'd like to have
1 form and a subject depending on the content of a select box... (like it is possible for all other text fields)
But perhaps this isn't possible...

Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 13:00
by Jensensen
Hi claus,
I had the same problem, but the solution can be like this:
The value of a selection is an array
. This is the reason, why it is not that easy to get the form value, which was selected.
[for me as an non php-speaking guy]
The certain values are read out of the form INTO --> $option_value by:
/include/inc_front/content/cnt23.article.inc.php
around lines 415 ff
Code: Select all
if(count($form_value)) {
foreach($form_value as $option_value) {
if(isset($POST_val[$POST_name]) && $POST_val[$POST_name] == $option_value) {
For my need I added a code snippet below, and it works.
Code: Select all
$myTEST = $option_value;
if($myTEST == 'SPOON') {
$myVAR = 1;
}
Now the option value is kept by additional variables $myTEST <--> $myVAR
For your case try to use
Code: Select all
$myTEST = $option_value;
if($myTEST == 'SPOON') {
$myVARa = 1;
}
if($myTEST == 'FORK') {
$myVARb = 2;
}
then write the option value, (kept by $myTEST ???!!! [at this point]???) to subject variable:
Code: Select all
if($myVARa == 1;) {
$mySubject == 'SPOON';
}
if($myVARb == 2;) {
$mySubject == 'FORK';
}
Have a look around the 'sending mail' code lines 1199ff
Code: Select all
$mail->Subject = $cnt_form["subject"];
change
And yes, for sure, there IS a more elegant way to change the code/write PHP, but I don't know
Additionally information: frontend render works perfect, even with forms, mail text and so on [was tested]. So, you can use both, hacking php code into your file and and FE render, right as you need...
Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 16:00
by Jensensen
Once again, more generally to what happens here.
The FOR EACH expression
just writes back HTML CODE --> <option value=".... to built the [form] page [usually --> $content["all"] what in this file is done by --> $cnt_form ]
AS LONG
as all option values are processed.
At the end of this [FOR EACH] there is an HTML selection box back in the page.
The problem now is, that there is no operation like:
Opps --> Selection Box --> Yes --> this is selected --> remember the value or write it where else...
[you know what i mean??]
At this point the values play no role but just stay untouched to wrap HTML code around.
There is one case we could --> identify the selected option value !!??
In that case the selection box contains ' selected' [THIS WOULD BE EXACT THE $option_value WE NEED] it gets cut off and then added right back to the HTML construction/expression.
Code: Select all
} else {
$option_value = str_replace(' selected', '', $option_value);
$form_field .= '<option value="'.$option_value.'" selected="selected"';
Another suggestion, worth to be tested, could perhaps be to add $MySubject = $option_value; right below:
Code: Select all
} else {
$option_value = str_replace(' selected', '', $option_value);
$form_field .= '<option value="'.$option_value.'" selected="selected"';
$MySubject = $option_value;
BUT KEEP IN MIND:
this routine operates all forms and all option/select boxes!!!
So, what we need is an expression that just writes option_value to your additional variable [at the RIGHT moment].
I do NOT know, where to find or how to --> catch !!??
Something like:
IF
$POST_val[$POST_name] IS MY_SELECTION BOX [id]
get the selected value AND write into MY_VARiable
Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 17:24
by juergen
Hi .. why hacking good code ?
phpmailer is part of phpwcms, phpmailer is a class ...
$mail->Subject = "This is my Bla bla nr 3";
in this case: a little sricpt where all things get posted ...
Code: Select all
$mail->Subject = $_POST['somehundretmailsubjects'];
...
...
if(!$mail->Send()) {
echo 'Failed to send mail';
} else {
echo 'Mail sent';
}
...
anyway, I would do the form extra... butr leave the score clean
Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 17:40
by Jensensen
Finally, for your question I found a solution:
line 402:
Code: Select all
foreach($form_value as $option_value) {
if(isset($POST_val[$POST_name]) && $POST_val[$POST_name] == $option_value) {
add:
Code: Select all
$MySubject = html_specialchars($option_value);
or just:
if there are NO html_specialchars
// now send original message
line 1250
Code: Select all
// $mail->Subject = $cnt_form["subject"];
$mail->Subject = $MySubject;
WORKS!
also check lines 1191 ff
BEWARE!! NOW ALL SUBJECTS WILL HAVE TO BE SELECTED WITHIN THE FORM!!!!!
$cnt_form["subject"] WHEN EDITING YOUR FORM SUBJECT IS IGNORED!!!!
Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 20:00
by Jensensen
OH MY GOODNESS!
IT IS THAT EASY:
let's say you have a selection box named --> MyEmailSubject
then add to your form template --> {MyEmailSubject}
change /add
lines 1203ff AND
lines 1248ff in
/include/inc_front/content/cnt23.article.inc.php
Code: Select all
// $mail->Subject = $cnt_form["subject"];
if ($_POST['MyEmailSubject'] != '') {
$mail->Subject = $_POST['MyEmailSubject'];
} else {
$mail->Subject = $cnt_form["subject"];
}
DF6IH wrote:Hi .. why hacking good code ?...
with bad code by jensensen
Always think about it at least twice --> before using it!!
Finally I know what I wanted to: --> how to get/trigger/catch the value, which was chosen by a selection box.
Thank you, DF6IH, for pointing one working solution out....
works also with sending mails by SMTP
@claus: still alive?

Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 20:07
by juergen
<ähem mode>
still hacking
</ähem>
This CLASS mailer has lots of functions...
http://www.tanmar.info/content/view/36/64/
it's the same in phpwcms as described within the link. Same extra Software as f.e. FCK Editor. And as CLASS it has lots of functions ..
lets say: $mail->body ='huahua'.$_POST['anything'].'days in orbit' ... and so on...
Just a poor html form ... and some script in frontend render and we can change subject as often as there are entries

Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 20:09
by juergen

Claus ran away... retired

Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 20:21
by update
@claus: still alive?
... and some script in frontend render and we can change subject as often as there are entries
Came back into my office just about one hour ago, had a look at my little rrs-phpwcmstopicreader, had a look into the forum, immediately felt very dizzy, fell back into my seat - thinking, tried to get a solution myself using your postings as a guide, entered the forum again, felt dizzy even more (my little solutionary thoughts had been somewhat similarly though

)....
BUT NOW
The solution(s) seem to be so near
as often as there are entries
With radio buttons too?

Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 20:23
by update
Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 20:33
by Jensensen
[ot]
@DF6IH
Sorry, BEVOR es da zu Misverständnissen kommt -- mit dem zweimal nachdenken!!
wollte NUR sagen [meinte], das jeder, der [jemals] --> meinen PHP-Code irgendwie nutzen/einbauen will --> im Zweifel --> immer vorsichtig sein muss, also zweimal mindestens tief rein schauen sollte, bevor er/sie davon was übernimmt, weil ich --> kann/spreche kein PHP!!!!
war insofern nur scherzhaft gemeint!!!
[/ot]
Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 20:41
by Jensensen
claus wrote:...With radio buttons too?...
should work as well [now, finally]
http://forum.phpwcms.org/viewtopic.php?p=97975#p97975
Jensensen wrote:...let's say you have a selection box named --> MyEmailSubject
then add to your form template --> {MyEmailSubject}...
let's say you have a RADIO BUTTON named --> MyRbutton
then add to your form template --> {MyRbutton}
and add some of the code hacks....as described above
Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 21:05
by Jensensen
@DF6IH
There are some questions left over:
Have a look at /include/inc_ext/phpmailer/class.phpmailer.php
and your tanmar link:
Does
//Set subject of E-Mail
$mail->Subject = "First Mail";
override
$cnt_form["subject"]
???
What does the following expression mean? {in German}
if(isset($POST_val[$POST_name]) && $POST_val[$POST_name] == $option_value) {
...}
wenn da ist post_val....true UND post_val... gleich option_value ... true {
dann mach det so...}
[oder so ähnlich??]
means $POST_val[$POST_name] the same as $_POST['MyFormFieldVar_set_as_Name'];
?????
THANK YOU!!
Re: CP form: dynamic subject possible?
Posted: Fri 18. Jan 2008, 21:10
by update
Many thanks for that !!!
Just tried it with the MyEmailSubject and must simply say: it works like hell. And if I don't have a field like this - it is still working as per default:!:
Then I deleted my pull down and tried it with radio buttons, named them MyEmailSubject but they don't show up as a subject option. Seems that they are special animals, (you did already mention something like this in another post)
OK did some more testing:
Left the changed code as is
added two radio buttons MyEmailSubject
added a hidden field with value {MyEmailSubject}
now I am able to select the hidden field in the subject select box
sent test mails
is workin with radios too
