This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
[closed] text in box
Started 13 years ago by viewscope | 7 posts |
-
Can you have the text already in the field box? Like "Name" when you click in the box where "NAME" is the text disappears. When you click off of it it re appears again.
Posted 13 years ago # -
This can be done by customizing machform files. To do this, you can use the method that posted in here :
MachForm Support
Posted 13 years ago # -
Hi redityo,
I think that post may need to be updated. I followed it step by step and the text indeed does appear in the field and also disappears when you click in the field, however, when you click somewhere else the default text does not reappear automatically.
Mark
Posted 13 years ago # -
Hi Mark,
You need to add "blur" ( lost focus) event to the field indeed. To do this, you can change these code :
if ($form_id == 17) { $javascript_event = <<<EOT <script type="text/javascript" src="js/jquery/jquery-core.js"></script> <script type="text/javascript"> function reset_field(element_id) { if ($('#element_'+element_id).val() == 'name' || $('#element_'+element_id).val() == 'phone' || $('#element_'+element_id).val() == 'email' ){ $('#element_'+element_id).val(''); } } </script> EOT; }
into
if ($form_id == 17) { $javascript_event = <<<EOT <script type="text/javascript" src="js/jquery/jquery-core.js"></script> <script type="text/javascript"> function reset_field(element_id) { if ($('#element_'+element_id).val() == 'name' || $('#element_'+element_id).val() == 'phone' || $('#element_'+element_id).val() == 'email' ){ $('#element_'+element_id).val(''); $('#element_'+element_id).blur(function () { if ($('#element_'+element_id).val() == "") { //set default value when lost focus switch (element_id) { case "1" : $('#element_'+element_id).val('name'); break; case "2" : $('#element_'+element_id).val('phone'); break; case "3" : $('#element_'+element_id).val('email'); break; default : $('#element_'+element_id).val('null'); break; } } }); } } </script> EOT; }
That would make your default field text appear when lost focus and do not have any entry.
Don't forget to change the element id with yours.MachForm Support
Posted 13 years ago # -
oops, I posted the wrong code on the top. Unfortunately I cannot edit it. The top should have said:
2. Go to around line 1832 ~ 1827, you will see these code :
if($has_calendar){ $calendar_js = '<script type="text/javascript" src="js/calendar.js"></script>'; }else{ $calendar_js = ''; }
put these code exactly below that code. One for form id17 and one for form id 33
if ($form_id == 17) { $javascript_event = <<<EOT <script type="text/javascript" src="js/jquery/jquery-core.js"></script> <script type="text/javascript"> function reset_field(element_id) { if ($('#element_'+element_id).val() == 'name' || $('#element_'+element_id).val() == 'phone' || $('#element_'+element_id).val() == 'email' ){ $('#element_'+element_id).val(''); $('#element_'+element_id).blur(function () { if ($('#element_'+element_id).val() == "") { //set default value when lost focus switch (element_id) { case "1" : $('#element_'+element_id).val('name'); break; case "2" : $('#element_'+element_id).val('phone'); break; case "3" : $('#element_'+element_id).val('email'); break; default : $('#element_'+element_id).val('null'); break; } } }); } } </script> EOT; } if ($form_id == 33) { $javascript_event = <<<EOT <script type="text/javascript" src="js/jquery/jquery-core.js"></script> <script type="text/javascript"> function reset_field(element_id) { if ($('#element_'+element_id).val() == 'name' || $('#element_'+element_id).val() == 'phone' || $('#element_'+element_id).val() == 'email' ){ $('#element_'+element_id).val(''); $('#element_'+element_id).blur(function () { if ($('#element_'+element_id).val() == "") { //set default value when lost focus switch (element_id) { case "1" : $('#element_'+element_id).val('name'); break; case "2" : $('#element_'+element_id).val('phone'); break; case "3" : $('#element_'+element_id).val('email'); break; default : $('#element_'+element_id).val('null'); break; } } }); } } </script> EOT; }
Is this correct?
You can delete the above post if needed or modify it so people do not get confused.
Mark
Posted 13 years ago # -
Also, is there a way to have the "default values" NOT sent in the emails. For example, if I have an optional single line text field called "Best time to contact you" and I use the method above so that the default value text is in the field it shows up in the emails with the text "Best time to contact you" if the user does not input anything.
There must be some way to not have default values included in the emails?
I plan on writing up a tutorial on this and perhaps you guys can sticky it once I have everything down.
Mark
Posted 13 years ago # -
Yes, you can use the if .. else .. like that to put each script on each form. And regarding not send a default value in mail notification, you need to edit "includes/helper-functions.php" file and go to line 330 for this code :
foreach ($entry_details as $data){
then put these code exactly bellow that line
if ($form_id == 6) { //form 6 default value if ($data['element_id'] == 1 and $data['value'] == 'name') { $data['value'] = ''; } elseif ($data['element_id'] == 2 and $data['value'] == 'phone') { $data['value'] = ''; } if ($data['element_id'] == 3 and $data['value'] == 'email') { $data['value'] = ''; } }
MachForm Support
Posted 13 years ago #
Topic Closed
This topic has been closed to new replies.