/    Sign up×
Community /Pin to ProfileBookmark

how to validate a php general form?

Currently I am able to validate form fields (making sure that the user has entered some value for them), for those form elements which are generally statically, via static html.

However, some elements of the form are generated via the PHP server. How can I validate those?

Perhaps get the PHP server to generate Javascript? and generate a submit method? where the contents of the method are dependant upon the contents of the php generated form?

suggestions?

is there any javascript method which makes all form input fields to have a value? regardless of how many, and the names of each input field?

If so, I could just call that upon submittion..

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliDec 04.2003 — yes actually if you want all of the text fields to have some value,you can use something like this

var tfields = document.getELementByTagName("input");

//this will give you an array of all input elements,now go through them and enter any value in the typ="text"

var len = tfields.length;

for(var n=0;n<len;n++){

if(tfield[n].type!=null && tfield[n].type=="text"){

//set any value here

tfield[n].value="default";

}

}
Copy linkTweet thisAlerts:
@bobby_dummy_022authorDec 04.2003 — I tried that, and it does not work.

After some debugging and testing, I have worked our that the following line does not work:

var tfields = document.getElementByTagName("input");

getElementByTagName is not a core function...

after trying to find information about the "document" onject, and how it is created, and using which class? I could not find anything...

I am familiar with Java, however Javascript is new to me, and I am having trouble finding info about it.
Copy linkTweet thisAlerts:
@bobby_dummy_022authorDec 04.2003 — Khalid Ali, what exactly is that method?

why does this not work for me?

var tfields = document.getELementByTagName("input");
Copy linkTweet thisAlerts:
@PittimannDec 04.2003 — Hi!

Just some typos in the code. Try this:
<i>
</i>&lt;script language="JavaScript" type="text/javascript"&gt;
&lt;!--
function check(){
var tfields = document.getElementsByTagName("input");
//this will give you an array of all input elements,now go through them and enter any value in the typ="text"
var len = tfields.length;
for(var n=0;n&lt;len;n++){
if(tfields[n].type!=null &amp;&amp; tfields[n].type=="text"){
//set any value here
tfields[n].value="default";
}
}
}
//--&gt;
&lt;/script&gt;

Cheers - Pit
×

Success!

Help @bobby_dummy_022 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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