/    Sign up×
Community /Pin to ProfileBookmark

How do I post only certain fields from a form?

I’m working on a form where some fields are needed in the posted info, but depending on what they fill out, some are not. I’m not trying to hide the field from the user, just don’t want it there on the email that is sent when it posts. Been searching, but I’m not sure of the correct verbage to search for, so haven’t found it.

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@gaston9x19May 05.2005 — Can you access the email script and just not have it include some fields if those certain other fields satisfy some logical condition? Seems like that would be the most direct way to customize what's sent in the email.
Copy linkTweet thisAlerts:
@Warren86May 05.2005 — I believe that "disabled" fields will not be posted, but I'm not certain.

Test this by taking one of your fields and doing this:

<input type=text name="firstName" value="John Doe" disabled=true size=15>

Then post the form. See what happens.
Copy linkTweet thisAlerts:
@LisaeauthorMay 05.2005 — Its someone else's asp script that I'm supposed to use as is - can't touch it. Is there another way?
Copy linkTweet thisAlerts:
@gaston9x19May 05.2005 — As Warren said, if you disable a field, it won't be posted with the rest of the form data, but you said you want it to be posted, just not emailed, right?
Copy linkTweet thisAlerts:
@Warren86May 05.2005 — If that works, in your "validation" JS code you can set disabled to true for those fields.

if (something){document.forms['myForm'].phoneNumber.disabled = true}
Copy linkTweet thisAlerts:
@Warren86May 05.2005 — And, you DON'T need to include disabled=true or disabled=false in ANY of your fields. Just use JS to disable the ones that you don't want posted, depending upon the test(s) that you conduct. If this, then these are disabled, if that, then those are disabled.
Copy linkTweet thisAlerts:
@LisaeauthorMay 05.2005 — Yes, that causes it not to post when I put it in the field. (Which is what I wanted - that it not post - sorry I wasn't clear before gaston.)

Once again, you are awesome Warren. I'm trying to hide the posts from the unused "Role" lists from the form you helped me with earlier. Haven't got the "use JS to disable" part figured out yet, but it will have to wait until tomorrow.

Thank you both and goodnight!
Copy linkTweet thisAlerts:
@Warren86May 05.2005 — You're welcome. Take care.
Copy linkTweet thisAlerts:
@Warren86May 05.2005 — Maybe this will work for you.

<HTML>

<Head>

<Script Language=JavaScript>

var prevRole = "";

function showRole(currRole){

if (prevRole != ""){document.getElementById(prevRole).style.display='none'}
if (currRole != 0)
{document.getElementById(currRole).style.display='inline';
prevRole=currRole}
}

function disableRoles(isForm){

selectedRole = isForm.Department.selectedIndex;
if (selectedRole == 1)
{
document.getElementById('101').disabled = true;
document.getElementById('110').disabled = true;
return true;
}
if (selectedRole == 2)
{
document.getElementById('100').disabled = true;
document.getElementById('110').disabled = true;
return true;
}
if (selectedRole == 3)
{
document.getElementById('100').disabled = true;
document.getElementById('101').disabled = true;
return true;
}
else {
alert('Please choose a department');
return false;
}
}


</Script>

</Head>

<Body>

<form name="NewUser" method='post' action='workForm.asp' onsubmit="return disableRoles(this)">

<select name="Department" onchange="showRole(this.value)">

<option value="0" selected>Choose a Department</option>

<option value="100">100 Corporate General</option>

<option value="101">101 Corporate Restructuring</option>

<option value="110">110 Merchandising General</option>

</select>

<select id="100" style='display:none'>

<option value="D1_0000001">D1 Role 000001</option>

<option value="D1_0000010">D1 Role 000010</option>

<option value="D1_0000020">D1 Role 000020</option>

</select>

<select id="101" style='display:none'>

<option value="D2_0000001">D2 Role 000001</option>

<option value="D2_0000010">D2 Role 000010</option>

<option value="D2_0000020">D2 Role 000020</option>

</select>

<select id="110" style='display:none'>

<option value="D3_0000001">D3 Role 000001</option>

<option value="D3_0000010">D3 Role 000010</option>

<option value="D3_0000020">D3 Role 000020</option>

</select>

<br><br>

<input type=submit value="Submit">

</form>

</Body>

</HTML>
Copy linkTweet thisAlerts:
@LisaeauthorMay 06.2005 — I need a new adjective -- you're amazing! The form is working well now, thank you again.
×

Success!

Help @Lisae spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...