Forms, validation and standards
Posted: Fri May 15, 2009 12:05 am
Hi,
I'm brand new to PHP. I have experience programming in JSP and Java and having trouble getting similar functionality in PHP which is purely due to my lack of experience.
While my issue is very basic I'm sure, I've researched many sites and they all have different approaches and I'm curious to see if there is a standard practice or not.
I have a page with a form on it. I want the user to be able to fill out the form and submit. I'd then like to use PHP code to verify all the fields have been filled out properly. If there are errors, return to the form page with an error list and the form with the values the user submitted so they can correct it. Otherwise, I'd like the data to be saved to my database, but I've already got that part working.
Here is a code snippet of my form thus far. I don't know whether to set the action to the same page the form is located and process if $_POST['submit'] is set, or have it go to another page to process? I'm also assuming I'll have to have a 'value' attribute in each input tag and set it to a $_POST variable if errors are detected?
Any help or direction with this would be greatly appreciated.
Thanks,
Jason
I'm brand new to PHP. I have experience programming in JSP and Java and having trouble getting similar functionality in PHP which is purely due to my lack of experience.
While my issue is very basic I'm sure, I've researched many sites and they all have different approaches and I'm curious to see if there is a standard practice or not.
I have a page with a form on it. I want the user to be able to fill out the form and submit. I'd then like to use PHP code to verify all the fields have been filled out properly. If there are errors, return to the form page with an error list and the form with the values the user submitted so they can correct it. Otherwise, I'd like the data to be saved to my database, but I've already got that part working.
Here is a code snippet of my form thus far. I don't know whether to set the action to the same page the form is located and process if $_POST['submit'] is set, or have it go to another page to process? I'm also assuming I'll have to have a 'value' attribute in each input tag and set it to a $_POST variable if errors are detected?
Code: Select all
<form name="newsAdd" method="post" action="">
<label>Title: <input type="text" name="title"></label><br />
<label>Article:<br /><textarea name="article" cols="100" rows="20"></textarea></label><br />
<label>Publish: <input type="checkbox" name="publish"></label><br />
<input type="submit" value="Save"><input type="reset" value="Reset">
</form>
Thanks,
Jason