Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: Form Autofill?

  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Form Autofill?

    Could someone tell me why this isn't auto filling my email field?

    I'm using
    Code:
    document.getElementById("form_email").value = '<?php echo $userdata->user_email; ?>';
    to try and pre-fill the field but it's just not seeing the field right?

    The form's HTML is the following:
    Code:
    <form action="" name="SUBMITFORM" id="SUBMITFORM" method="post" onsubmit="return CheckFormData();" enctype="multipart/form-data">
    and the field:
    Code:
    <input type="text" name="form[email]" id="form_email" class="short" tabindex="4" value=""   />
    I know I'm missing something so simple, but I've tried, I really have....

    Thanks!

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    are you adding that code before of after the form on the page? If you are adding it in the head in a script block, just as you have it now, it wont work because the form doesnt exist in the dom yet.

    - why not simply fill the form value directly with your server side code, you don't even need the JavaScript for this.

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    It is in my head, but the form is dynamically created using PHP, and I want the value to be pulled from Wordpress, so it will be different for each user.....can I still do it that way?

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    ahh, ok, Im guessing you dont have acces to the code that generate the form or are perhaps unsure of where to edit it?

    - if you put your code in a script block at the bottom of the page, instead of the head, that should work as well.

  • Users who have thanked DanInMa for this post:

    DSchragg (11-26-2012)

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Actually I do know the file, and the code that creates the field, is there a way I can accomplish the same thing by adding something here?

    Code:
    	if($dfs['email'] != "1"){
    		$field[$o]['title'] 	= $PPT->_e(array('add','28'));
    		$field[$o]['name'] 		= "email";
    		$field[$o]['dataname'] 	= "email";
    		$field[$o]['type'] 		= "text";
    		$field[$o]['required'] 	= true;
    		$o++;
    	}
    Thanks for your help!

  • #6
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    im not a php coder bu jsut looking at it, I would guess:



    Code:
    	if($dfs['email'] != "1"){
    		$field[$o]['title'] 	= $PPT->_e(array('add','28'));
    		$field[$o]['name'] 		= "email";
    		$field[$o]['dataname'] 	= "email";
    		$field[$o]['type'] 		= "text";
    		$field[$o]['required'] 	= true;
    		$field[$o]['value'] 	= $userdata->user_email;
    		$o++;
    	}

  • #7
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    This didn't work, but moving the javascript to the footer did the trick....

    Thanks again for your help!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •