Appnitro Software Forums » MachForm 2

Showing default values that disappear once a user clicks in the field


  1. raewell
    Member

    I am trying to edit a clients form (they are using MachForm). They want the form to display like the form on this site... http://www.pdxsmiles.com/

    They are trying to condende the existing form they have to open up space. They feel that instead of using a label like "Name:" next to or above the feild, they want the default value listed in the field. When the user clicks in the field, the default value disappears allowing them to enter the info.

    Any suggestions would be appreciated.

    Raewell

    Posted 2 years ago #
  2. redityo

    Hi Raewell,

    I think it could be done, let's say your 3 field information is like this :

    * full name : element 1, default value is name
    * phone : element 2, default value is phone
    * email : element 3, default value is email

    I assume all filed on form id 17, Then you need to edit "includes/view-functions.php", try to follow these steps :

    1. Go to around line 40 ~ 50, you will see these code :

    $element_markup = <<<EOT
    		<li id="li_{$element->id}" {$error_class}>
    		<label class="description" for="element_{$element->id}">{$element->title} {$span_required}</label>
    		<div>
    			<input id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="text" value="{$element->default_value}" />
    		</div>{$guidelines} {$error_message}
    		</li>
    EOT;

    replace with these one

    if ($_GET['id'] == 17) {
    	if ($element->id == 1 || $element->id == 2 || $element->id == 3 ) {
    		$onclick_event = ' onclick="javascript:reset_field(\''.$element->id.'\')" ';
    	}
    }
    
    $element_markup = <<<EOT
    		<li id="li_{$element->id}" {$error_class}>
    		<label class="description" for="element_{$element->id}">{$element->title} {$span_required}</label>
    		<div>
    			<input {$onclick_event} id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="text" value="{$element->default_value}" />
    		</div>{$guidelines} {$error_message}
    		</li>
    EOT;

    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 bellow that 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;
    }

    3. Go to line 1855, you'll see

    <script type="text/javascript" src="js/view.js"></script>

    then put this code bellow that line

    {$javascript_event}

    Don't forget to change those id with yours


    MachForm Support

    Posted 2 years ago #
  3. raewell
    Member

    Thank you so much for the quick reponse. I tried the solution but ended up with an error. I know it was a mistake I made so if you (or anyone else) can look at the form on the right hand side of www.renewingsmiles.com . The form id is 5.

    I think I need to know exactly what to replace in the above solution so this will work.

    If you could use any other info from me, I will get it to you right away.

    I really appreciate your assistance and enjoy working with your product.

    Posted 2 years ago #
  4. Hello raewell,

    Can you send us your modified "includes/view-functions.php" file please?
    We'll check it.

    Please send to: customer.service [at] appnitro.com


    MachForm Founder

    Posted 2 years ago #
  5. raewell
    Member

    I have just sent the file to the address.

    What great customer service ! I really appreciate this assitance.

    Raewell Graphics

    Posted 2 years ago #
  6. I've also implemented this tweak (perhaps it could come as standard?)

    line 44 of includes/view-functions.ph

    From:

    <input id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="text" value="{$element->default_value}" />

    To:

    <input id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="text" value="{$element->default_value}" onclick="this.value='';" />

    Posted 1 year ago #
  7. Machmail
    Member

    hotchecks there is a better solution, which will reset only the default field value:

    Save this code into file js\reset_field.js:

    function resetBox(box, defaultvalue) {
    	if (box.value == defaultvalue) {
    		box.value = "";
    	}
    }

    Near line 50 in includes\view-functions.php change

    from:

    <input id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="text" value="{$element->default_value}" />

    to:

    <input id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="text" value="{$element->default_value}" onclick="resetBox(this, '{$element->default_value}')" />

    Near line 1850 in includes\view-functions.php change

    from:

    <link rel="stylesheet" type="text/css" href="{$css_dir}view.css" media="all" />
    <script type="text/javascript" src="js/view.js"></script>

    to:

    <link rel="stylesheet" type="text/css" href="{$css_dir}view.css" media="all" />
    <script type="text/javascript" src="js/view.js"></script>
    <script type="text/javascript" src="js/reset_field.js"></script>
    Posted 8 months ago #
  8. Great !
    Thank you Machmail

    Posted 6 months ago #

RSS feed for this topic

Reply