Jump to content

Help with php and forms


tvtg

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.