...

View Full Version : Form Autofill?



DSchragg
11-25-2012, 08:49 PM
Could someone tell me why this isn't auto filling my email field?

I'm using
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:
<form action="" name="SUBMITFORM" id="SUBMITFORM" method="post" onsubmit="return CheckFormData();" enctype="multipart/form-data"> and the field:
<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!

DanInMa
11-25-2012, 08:52 PM
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.

DSchragg
11-25-2012, 08:55 PM
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?

DanInMa
11-25-2012, 09:35 PM
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.

DSchragg
11-25-2012, 10:45 PM
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?


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!

DanInMa
11-25-2012, 11:56 PM
im not a php coder bu jsut looking at it, I would guess:




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++;
}

DSchragg
11-26-2012, 12:49 AM
This didn't work, but moving the javascript to the footer did the trick....

Thanks again for your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum