/    Sign up×
Community /Pin to ProfileBookmark

PHP Equivalent of getElementById

Hello everyone,

As a number of mobile browsers sometimes turn off javascript I am trying to perform form field validation using php and want to build an array function that processes through all form field elements by id of the form for appropriate validations checks against some regex functions I’ve built.

Anyone have any suggestions / solutions for a php equivalent of getElementById as I would like to keep the id as an integer and preserve form field name as text?

Jason

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@andre4s_yFeb 22.2009 — Big question :

You want to do the validation in client side or server side?

PHP is server side programming.

JavaScript is client side programming.

You can use input tag like
[code=html]
<input name="test" id="test" type="text" value="testing" />
[/code]

PHP will recognize its value in $_GET['test'] or $_POST['test'] depend on your form method.

JavaScript will recognize its value in document.getElementById('test').value;

Both PHP and JavaScript can do validation using "some regex functions".

?

Hope this helps..
Copy linkTweet thisAlerts:
@NogDogFeb 22.2009 — [url=http://www.php.net/manual/en/domdocument.getelementbyid.php]DOMDocument::getElementById[/url]
Copy linkTweet thisAlerts:
@Hokie1200authorFeb 23.2009 — I want to perform server side validation where Javascript may be disabled. As such what I want to do is build an array of a group of form input fields, apply some regex checks on each and raise an error and highlight using CSS in case of any errors. The only way I could think of is to set the name of each field as number and ascending or somehow utilize the id fields to include a numeric value and text field as whatever name I want and step through the array based on the id of form field. I am pretty confident that this is possible with Javascript, but trying to apply the same concept to php. Based on your experience what is the best practice for this as the particular form I am developing to will also be used on mobiles where sometimes Javascript may not be enabled or supported.
Copy linkTweet thisAlerts:
@MindzaiFeb 23.2009 — There's no need to do that, php will receive submitted form data automatically in its $_GET or $_POST superglobals depending on the method specified in the form. If you want to highlight errors you could just populate an array with the name of all invalid fields, then in your form display code place some logic to check if the name of the current form field exists in the errors array.
×

Success!

Help @Hokie1200 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,
)...