Forum Moderators: open

Message Too Old, No Replies

What to Do!?!?!?

         

prozaac

11:21 am on Jul 28, 2004 (gmt 0)

10+ Year Member



been posting this question before, still, i haven't recieved an answer that really helps me...

want to exclude empty textfields in mail that i recieve when user submits a form to me...
in the form it is allowed to leave empty textfields, and it should be..

so -->> i don't want the empty ones listed in my mail.

suggestions? examples? good hints?

anything, please! (i believe i've browsed through every page on the net...)

encyclo

11:28 am on Jul 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are using a formmail-type script to send the form to you, then there is nothing you can do with Javascript which will make any difference - because Javascript has no influence on the form-sending process but rather is just doing basic client-side validation.

If you want to exclude emply fields, you will need to alter your mailing script (probably written in Perl, PHP or similar server-side language).

prozaac

11:33 am on Jul 28, 2004 (gmt 0)

10+ Year Member



are u sure, you, got a tip before, something with removechild()...

maybe with some if- that will be possible? since you can do all the validation n stuff, maybe there is a way with that?

natty

11:33 am on Jul 28, 2004 (gmt 0)

10+ Year Member



hi there,

you could validate the form :
<form .... onsubmit="return validateForm(this);" ...>

function validateForm(oFrm){
var fld;
for(x=oFrm.elements.length;x==0;x--){
fld =oFrm.elements[x];
if(fld.value ==""){
oFrm.removeChild(fld);
}
}
return true;
}

havent checked this but should work..(he says)
a bit of a hack, but sounds like what u want.
and of course wont work with a non DOM browser.
i know that there is no return false for failed validation, but mbe u can add that urself.
HTH

nat

[edited by: natty at 11:42 am (utc) on July 28, 2004]

prozaac

11:37 am on Jul 28, 2004 (gmt 0)

10+ Year Member



nat! that sounds just about right, but i'm not sure what to put in the ( )

should that be the field am checkin? what if there are is more than one filed that is left empty....

do i need to declare variables...
functions and so on

you have to excuse me, im not very good at this..

/prozaac

prozaac

11:38 am on Jul 28, 2004 (gmt 0)

10+ Year Member



nat!

you know of any good pages that will explain this further?

/prozaac

natty

11:44 am on Jul 28, 2004 (gmt 0)

10+ Year Member



amended my previous post.. giveit a go

gl

prozaac

11:47 am on Jul 28, 2004 (gmt 0)

10+ Year Member



you are a lifesaver, will check that code right now!

prozaac

12:54 pm on Jul 28, 2004 (gmt 0)

10+ Year Member



nat..or who ever, doesn't seem to work...this is what my example for would look like, with proper names...

<form name="carlsberg" method="post" onsubmit="return validateForm(this)" action="mailto:se.sommar33fbg@carlsberg.se">

<input type="text" name="ol" value=""></input><p>
<input type="text" name="vin" value=""></input><p>
<input type="text" name="sprit" value=""></input><p>
<input type="submit">Bekräfta</input>

</form>

how on earth would implement the code given

natty

5:33 pm on Jul 28, 2004 (gmt 0)

10+ Year Member



in case you havent managed it

although this doesnt check to see if nothing has been entered.. which may be worth doing ;)


<html>
<head>
<script type="text/javascript">
function validateForm(frm){
for(var x=frm.elements.length-1;x>-1;x--){
if(frm.elements[x].type =="text"){
(frm.elements[x].value=="")? frm.removeChild(frm.elements[x]):null;
}
}
}
</script>
</head>
<body>
<form name="f1" onsubmit="validateForm(this);" method="post" action="mailto:someone@emailgoeshere.com">
<input type="text" name="ol" value=""><br>
<input type="text" name="vin" value=""><br>
<input type="text" name="sprit" value=""><br>
<input type="submit" value="send it"><br>
</form>
</body>
</html>

prozaac

7:12 pm on Jul 28, 2004 (gmt 0)

10+ Year Member



thanx natty! looks so obvious when you have it in front of you...

thx for the help!

prozaac

9:34 am on Jul 29, 2004 (gmt 0)

10+ Year Member



Code works fine and all natty, but when i want to put the texfields in, let's say different <td>'s then it won't work.......
so basically i'd have to make one hell of a long vertical list of texfields in order for it to work properly....

any solutions..?

/Prozaac

prozaac

10:16 am on Jul 29, 2004 (gmt 0)

10+ Year Member



so basically i need it to include all fields on the page, even in different tables... possible?ofcourse, but how!?!

/prozaac

natty

1:50 pm on Jul 29, 2004 (gmt 0)

10+ Year Member



hi prozac,

sounds like you have text fields in more than one form, as that should work for all inputs in a single form.

can call it again from the second form mbe..

ofc i may be miles off..

gl

prozaac

9:33 am on Jul 30, 2004 (gmt 0)

10+ Year Member



well, actually i'm using the same form, just split the textfields up in differnet tables..., still only have one submit button as i want... but the textfiels in the first table column gets left out...

so what i'm asking, is... is there a way to split up the same form in differnet coulumn and still run through them with the same funtion as i have now?...

(check the funtion in previous post)....

i've tried as hard as i can, but since i suck at it i've come up with no solution... what to do...