tvtg Posted February 22, 2010 Share Posted February 22, 2010 Hi, Im total new in PHP and HTMl programming - any help will be welcome What Im trying to do is I have a main.html file with form on the form there is one button and the code is as follow: <INPUT type="button" class="buttons" value="Add Stuff" onClick="window.open('AddStuff.php','New Stuff', 'width=100%,height=100%')"> Now what I want to happen is that AddStuff.php will contain both html form and php code that will validate Form fields before inserting the values to MySQL My problem is how the php file should be build is it : <?php do some PHP validations here and if OK send to the SQL DB > <html> <head> head stuff </head> <body> <form name="newStuff" action="AddStuff.php" method="post" onSubmit="return validateNewStuffForm()"> ...form stufff .... </form> </body> </html> if I put it this way the php stuff is called also when I open the window Please help in how to arange the php file in a way that : 1) html file will be opened 2) form will be filled 3) php procedures on the same file will called 4) How do I close the window when php procedures were done successfully Thanks in advance for all your help T Link to comment https://forums.phpfreaks.com/topic/192944-help-with-php-and-forms/ Share on other sites More sharing options...
WolfRage Posted February 23, 2010 Share Posted February 23, 2010 PHP is server side, if you want to submit a form to the server than do so and check it using PHP on the server side. Then if the results are good take them to a completion page else send them back to the form and highlight the improper field(s). There is no opening and closing windows using PHP that is javascript. Link to comment https://forums.phpfreaks.com/topic/192944-help-with-php-and-forms/#findComment-1016633 Share on other sites More sharing options...
jay7981 Posted February 23, 2010 Share Posted February 23, 2010 for an example of valadation code and a processor see my post here note that i am having issues with the processor but only the sql query, the validation is working perfectly. Link to comment https://forums.phpfreaks.com/topic/192944-help-with-php-and-forms/#findComment-1016637 Share on other sites More sharing options...
aleX_hill Posted February 23, 2010 Share Posted February 23, 2010 Personally I would do it this way from AddStuff.php if(isset($_POST['variable'])) //If there is a POST variable sent, process the data. Change variable to the id of your submit button { //Do your validation stuff here } else { //Nothing submitted, show the form ?> <html> <head> etc. <?php } //Close the else ?> To make it a bit more complex, put the drawing of the form in a function like so: function drawForm($errorMessage) { //HTML for form here } That way, if you get an error in validation in the PHP you can send through an error message to the form when you create it. Link to comment https://forums.phpfreaks.com/topic/192944-help-with-php-and-forms/#findComment-1016643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.