Hello there,
I have a dropdown item [contact] that let's the user select between email, telephone and two internet platforms. After that, there's a contact textbox [contact-info] which should automatically be filled:
[list][*]If the user selects email, the contact textbox value should be set to $user->email
[*]If the user selects telephone, the contact textbox value should be set to $user->telephone
[*]If the user selects a internet platform, the contact textbox value should be set to the name of the internet platform and the readonly param should be added[/list]
I tried the events in [contact] with "Set Options" and "value ="<?php $user->email; ?>", but it didn't work. Dynamic Options didn't work either.
Is this possible to solve? What do I have to do?
Thanks in advance
Christian
I have a dropdown item [contact] that let's the user select between email, telephone and two internet platforms. After that, there's a contact textbox [contact-info] which should automatically be filled:
[list][*]If the user selects email, the contact textbox value should be set to $user->email
[*]If the user selects telephone, the contact textbox value should be set to $user->telephone
[*]If the user selects a internet platform, the contact textbox value should be set to the name of the internet platform and the readonly param should be added[/list]
I tried the events in [contact] with "Set Options" and "value ="<?php $user->email; ?>", but it didn't work. Dynamic Options didn't work either.
Is this possible to solve? What do I have to do?
Thanks in advance
Christian
Hi Christian,
You will need to use "Function" under the "Events" and your function will have to be defined under a "Load JavaScript" action like this:
Regards,
Max
You will need to use "Function" under the "Events" and your function will have to be defined under a "Load JavaScript" action like this:
function fill_the_field(){
<?php $user = JFactory::getUser(); ?>
if ($("#dropdown_id").val() == "email") {
$("#textbox_id").val("<?php echo $user->get('email'); ?>");
}
}
Regards,
Max
Hi Max,
thanks for your reply, but it's still not working.
Here's what I put in the Load JavaScript / JS Code:
The dropdown options contain:
And in the "events" tab of "contact" I put it like this (for all four possibilities):
[attachment=0]events.jpg[/attachment]
I don't get it! What is wrong?
I also tried onchange=contact_fill() in the params field of contact - it didn't work!
(Could it be the same problem as in this question)
thanks for your reply, but it's still not working.
Here's what I put in the Load JavaScript / JS Code:
function contact_fill(){
<?php $user = JFactory::getUser(); ?>
if($("contact").val() == "Email"){
$("contact-info").val("<?php echo $user->get('email'); ?>");
}
if($("contact").val() == "Tel"){
$("contact-info").val("<?php echo $user->get('telephone'); ?>");
}
if($("contact").val() == "nachbarschaftsauto"){
$("contact-info").val("www.nachbarschaftsauto.de");
}
if($("contact").val() == "autonetzer"){
$("contact-info").val("www.autonetzer.de");
}
}
The dropdown options contain:
Email=Email
Tel=Telefon/Handy
nachbarschaftsauto=über www.nachbarschaftsauto.de
autonetzer=über www.autonetzer.de
And in the "events" tab of "contact" I put it like this (for all four possibilities):
[attachment=0]events.jpg[/attachment]
I don't get it! What is wrong?
I also tried onchange=contact_fill() in the params field of contact - it didn't work!
(Could it be the same problem as in this question)
Yes, same answer like the other question, please change the elements references:
Regards,
Max
$("#field_id") OR BETTER: jQuery("#field_id")
Regards,
Max
I tried on both parts, it doesn't work! I still get nothing.
I now use a Web Developer Tool to see if the script or the call produces errors; it seems it doesn't.
This is the code now:
I also tried jQuery("#contact"), although I don't think that's what you wanted to say. It doesn't work either.
In the function event in "contact" I tried to put JavaScript:contact_fill() instead of only contact_fill() - no results.
I don't know what to do. Is it some basic mistake?
Perhaps I may send it to you via PM ...?
Regards,
Christian
I now use a Web Developer Tool to see if the script or the call produces errors; it seems it doesn't.
This is the code now:
function contact_fill(){
<?php $user = JFactory::getUser(); ?>
if(jQuery("contact").val() == "Email"){
jQuery("contact-info").val("<?php echo $user->get('email'); ?>");
}
if(jQuery("contact").val() == "Tel"){
jQuery("contact-info").val("<?php echo $user->get('telephone'); ?>");
}
if(jQuery("contact").val() == "nachbarschaftsauto"){
jQuery("contact-info").val("www.nachbarschaftsauto.de");
}
if(jQuery("contact").val() == "autonetzer"){
jQuery("contact-info").val("www.autonetzer.de");
}
}
I also tried jQuery("#contact"), although I don't think that's what you wanted to say. It doesn't work either.
In the function event in "contact" I tried to put JavaScript:contact_fill() instead of only contact_fill() - no results.
I don't know what to do. Is it some basic mistake?
Perhaps I may send it to you via PM ...?
Regards,
Christian
Hi Christian,
It must be:
You can test if the function is getting called by adding this line after the function start:
Let me know!
Regards,
Max
It must be:
jQuery("#contact")
and your field "id" should be set to "contact" in order for it to work!
You can test if the function is getting called by adding this line after the function start:
alert("test");
Let me know!
Regards,
Max
Hi Max,
I tried the alert thing, it works. Everytime I change the option, the function is definitely called.
I printed out debugging info, here it is. Perhaps it helps:
Here's the actual JS Code:
And here's the relevant setup part:
[attachment=0]entry-part.jpg[/attachment]
Regards,
Christian
I tried the alert thing, it works. Everytime I change the option, the function is definitely called.
I printed out debugging info, here it is. Perhaps it helps:
Data Array
Array
(
[chronoform] => Carsharing-Eintrag
[event] => page3
[contact] => Email
[contact-info] => doesnot@work.de
[contact-details] =>
[captcha] =>
[submit] => Absenden
[name] => Mustermann, Thomas
[car] => Citroen Berlingo
[ort] => 77777 Musterstadt
[gearsys] => Handschaltung
[fuel] => Benzin
[type] => Kombi
[class] => M
[car-details] => Rücksitzbank ausgebaut!
[page2] => Weiter
[available] => auf Anfrage - bitte mindestens eine Woche im Voraus
[time-standard] => 2.5
[time-long] => 2.3
[km_standard] => 9
[km_long] => 7
[kaution] => 70
[pfand] =>
[price-details] =>
[page3] => Weiter
[id] => 4
)
Array
(
)
Errors
Array
(
)
Debug Info
Array
(
[16] => Array
(
[DB Save] => Array
(
[Queries] => Array
(
[0] => INSERT INTO `kwm_car_offers` (`contact`, `contact-info`, `contact-details`, `name`, `car`, `ort`, `gearsys`, `fuel`, `type`, `class`, `car-details`, `available`, `time-standard`, `time-long`, `km_standard`, `km_long`, `kaution`, `pfand`, `price-details`, `user_id`, `created`) values ('Email', 'doesnot@work.de', '', 'Mustermann, Thomas', 'Citroen Berlingo', '77777 Musterstadt', 'Handschaltung', 'Benzin', 'Kombi', 'M', 'Rücksitzbank ausgebaut!', 'auf Anfrage - bitte mindestens eine Woche im Voraus', '2.5', '2.3', '9', '7', '70', '', '', '513', '2014-08-19 21:42:00');
)
)
)
)
Here's the actual JS Code:
function contact_fill(){
alert("test");
<?php $user = JFactory::getUser(); ?>
if(jQuery("#contact").val() == "Email"){
jQuery("#contact-info").val("<?php echo $user->get('email'); ?>");
}
if(jQuery("#contact").val() == "Tel"){
jQuery("#contact-info").val("<?php echo $user->get('telephone'); ?>");
}
if(jQuery("#contact").val() == "nachbarschaftsauto"){
jQuery("#contact-info").val("www.nachbarschaftsauto.de");
}
if(jQuery("#contact").val() == "autonetzer"){
jQuery("#contact-info").val("www.autonetzer.de");
}
}
And here's the relevant setup part:
[attachment=0]entry-part.jpg[/attachment]
Regards,
Christian
Ok, 1 more test, inside this section:
Please try:
if(jQuery("#contact").val() == "Email"){
Please try:
alert("<?php echo $user->get('email'); ?>");
Good idea, I tried - and got nothing. So it seems the if-clause is not positive.
I tried two more things before the section:
The user email is definitely there.
But when I try to "alert" the jQuery part, the site breaks with the following message:
**Revision: seemed to be a syntax error, now I only get an empty alert box. I also tried without #, and with $ instead of jQuery, only empty boxes or nothing.
I also tried to get somethins via PHP, like
but this only get me an empty alert box.
The field's name definitely is contact.
What now?
I tried two more things before the section:
The user email is definitely there.
But when I try to "alert" the jQuery part, the site breaks with the following message:
function contact_fill(){ alert("
Fatal error: Call to undefined function jQuery() in C:\xampp\htdocs\mobil\administrator\components\com_chronoforms5\chronoforms\actions\js\js.php(33) : eval()'d code on line 3
**Revision: seemed to be a syntax error, now I only get an empty alert box. I also tried without #, and with $ instead of jQuery, only empty boxes or nothing.
I also tried to get somethins via PHP, like
alert("<?php echo $form->data['contact']; ?>");
,
but this only get me an empty alert box.
The field's name definitely is contact.
What now?
I'm not sure how you tried to alert the jQuery part, please move the alert line I posted outside the if statement, does it work ?
Can you find the email address in the page source ?
Can you find the email address in the page source ?
Well, I first tried inside, as you suggested, and nothing happened (just the first line of my comment). Then I tried it outside, like in the code below.
By page source, I suppose you mean this:
So yes, the needed userinfo is there. But as the alert box is empty, none of the ifs will be entered. So there must be something wrong with the syntax!? jQuery("#contact").value (I tried .val() too, same result).
By page source, I suppose you mean this:
<script type="text/javascript">function contact_fill(){
alert(jQuery("#contact").value);
if(jQuery("#contact").val() == "Email"){
jQuery("#contact-info").val("muster@muster.com");
}
if(jQuery("#contact").val() == "Tel"){
jQuery("#contact-info").val("07777 77777");
}
if(jQuery("#contact").val() == "nachbarschaftsauto"){
jQuery("#contact-info").val("www.nachbarschaftsauto.de");
}
if(jQuery("#contact").val() == "autonetzer"){
jQuery("#contact-info").val("www.autonetzer.de");
}
}
So yes, the needed userinfo is there. But as the alert box is empty, none of the ifs will be entered. So there must be something wrong with the syntax!? jQuery("#contact").value (I tried .val() too, same result).
So we now know that the PHP is working correctly, you will need to replace this line:
by
And check the console window for the output, what does it show ?
The "contact" field has a field id = "contact", correct ? and its the field which has the "contact_fill" function under "Events" right ?
Regards,
Max
alert(jQuery("#contact").value);
by
console.log(jQuery("#contact"));
And check the console window for the output, what does it show ?
The "contact" field has a field id = "contact", correct ? and its the field which has the "contact_fill" function under "Events" right ?
Regards,
Max
console.log shows this. It's partly in german, I hope thats not a problem. I think the relevant lines must either be the second and third or the last two (showed up when I changed):
And yes, the id is "contact". Here's a picture, for reassurance:
[attachment=0]contact.jpg[/attachment]
I posted a picture of the events tab in "contact" in an earlier comment. I checked this twice and trice because I'm also afraid it is some simple mistake. But it doesn't seem so...
getUserData() und setUserData() sollten nicht mehr verwendet werden. Verwenden Sie stattdessen WeakMap oder element.dataset. requestNotifier.js:63
Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead jquery.js:1
http://localhost/mobil/libraries/cegcore/assets/jquery/jquery.js is being assigned a //# sourceMappingURL, but already has one
Sicherheitsfehler: Inhalt auf http://localhost/mobil/index.php/carsharing/auto-eintragen?chronoform=Carsharing-Eintrag&event=page2 darf resource://firefox.abs.avira.com/html/top.html#minimized nicht laden oder verlinken.
Synchrone XMLHttpRequests am Haupt-Thread sollte nicht mehr verwendet werden, weil es nachteilige Effekte für das Erlebnis der Endbenutzer hat. Für weitere Hilfe siehe http://xhr.spec.whatwg.org/ app.js:3
nicht wohlgeformt indexed.json:1
nicht wohlgeformt en-US.json:1
nicht wohlgeformt de-DE.json:1
getPreventDefault() sollte nicht mehr verwendet werden. Verwenden Sie stattdessen defaultPrevented. jquery.js:5
A promise chain failed to handle a rejection.
Date: Wed Aug 20 2014 19:38:00 GMT+0200
Full Message: false
A promise chain failed to handle a rejection.
Date: Wed Aug 20 2014 19:39:19 GMT+0200
Full Message: false
And yes, the id is "contact". Here's a picture, for reassurance:
[attachment=0]contact.jpg[/attachment]
I posted a picture of the events tab in "contact" in an earlier comment. I checked this twice and trice because I'm also afraid it is some simple mistake. But it doesn't seem so...
Hi Christian,
Sorry for the delay, I suggest that you install the FireBug extension on FireFox and test this for errors, your code and settings look correct to me, or send me a link to the form so I can check it!
Regards,
Max
Sorry for the delay, I suggest that you install the FireBug extension on FireFox and test this for errors, your code and settings look correct to me, or send me a link to the form so I can check it!
Regards,
Max
Hi Max,
I solved it!! The syntax does not seem to be correct.
I've been using firebug for a long time now. But by chance I saw in the script how the events in my dropdown field were coded in js. It was like
So I tried this with my script and it worked!! Here is the solution:
...
This also works with models, like I've done in this problem.
Christian
I solved it!! The syntax does not seem to be correct.
I've been using firebug for a long time now. But by chance I saw in the script how the events in my dropdown field were coded in js. It was like
$("[name='contact']")
So I tried this with my script and it worked!! Here is the solution:
function contact_fill(){
<?php $user = JFactory::getUser(); ?>
if(jQuery("[name='contact']").val() == "Email"){
jQuery("[name='contact-info']").val("<?php echo $user->get('email'); ?>");
}
if(jQuery("[name='contact']").val() == "Tel"){
jQuery("[name='contact-info']").val("<?php echo $user->get('telephone'); ?>");
}
if(jQuery("[name='contact']").val() == "nachbarschaftsauto"){
jQuery("[name='contact-info']").val("www.nachbarschaftsauto.de");
}
if(jQuery("[name='contact']").val() == "autonetzer"){
jQuery("[name='contact-info']").val("www.autonetzer.de");
}
}
...
This also works with models, like I've done in this problem.
Christian
Well, this is weird, I would love to know why jQuery("#contact") didn't work but jQuery("[name='contact']") worked!
Do you have an empty space after the id in the field settings maybe ?
Do you have an empty space after the id in the field settings maybe ?
Definitely not! I checked that over and over again while searching for a solution.
But it seems CF-core is also using this syntax as it was printed out like this in the source code.
Should both syntaxes work? Well, I don't know much about that, I only know it works now🙂.
But it seems CF-core is also using this syntax as it was printed out like this in the source code.
Should both syntaxes work? Well, I don't know much about that, I only know it works now🙂.
Yes, both should work, but CF core uses this syntax when only the field name is available to the code, but if you have the id then its supposed to use the one with id!
This topic is locked and no more replies can be posted.