Computing.Net > Forums > Programming > PHP Script and HTML Forms

PHP Script and HTML Forms

Reply to Message Icon

Original Message
Name: pymphar
Date: August 24, 2003 at 23:59:03 Pacific
Subject: PHP Script and HTML Forms
OS: win 2k
CPU/Ram: 256mb
Comment:

Hi. I am having difficulty with a small PHP program I am working on. I have 2 forms on 1 HTML file, pointing their actions to 2 different PHP scripts.

The problem is, once I submit the contents of the first form on that HTML file to be processed by the first PHP script, I loose data (it goes blank) on the HTML file before I get a chance to process the data with the second script. Is there a way to run the first php script and process the first form and then come back and still have the data on it so I can process the 2nd php script?

Basically, its a user information program... one php script is to process user record information and I have a second php script used to upload the user's image, both forms are on the same page. When I type the user information in in the first form, then I go to the 'browse for picture' form then click the upload button to send the picture to the ftp server, it goes to a confirmation page to confirm the upload. When I click back to get to the form, the page's form content is gone. I also need to acquire the name of the picture selected from the 2nd PHP script to be used as a string that contains the pictures name in the first form.

Any suggestions?

Thnx.

Pymphar


Report Offensive Message For Removal


Response Number 1
Name: Don Arnett
Date: August 25, 2003 at 01:30:25 Pacific
Subject: PHP Script and HTML Forms
Reply: (edit)

I don't do PHP, but don't think that this is a PHP specific problem. By that I mean that I believe that you'd have the same problem regardless of what server side language you are using. The problem is related more to how HTML forms work with the server side program.

Basically, when you submit a form, the form's data is sent to the server, which does whatever with it and then sends back a new page. It sounds like you are sending back the 'same' page, but when you send it back the data from the second page is lost because the server side script isn't sending it back.

So, I believe that your solutions are:

- send the second form info along with the first form info, so that the script can redisplay the data when it resends the page. This could be done by 1) combining both forms into one and letting the PHP program handle both together or call the other program, etc or 2) when a submit button is pressed, having each form make for itself a copy of the other form's data that can be sent (you'd do this with javascript and hidden fields).

Another option (I think the preferred option if you don't want to combine the two forms into one) would be to put the two forms on separate pages. When they submit the user info form, it returns the blank picture submit form on a new page and the user processes that form.

I just re-read your post and the 'back' button part. I think that making this two pages is your best bet. You don't want the user to have to press the 'back' button.


Report Offensive Follow Up For Removal

Response Number 2
Name: Infinite Recursion
Date: August 25, 2003 at 06:59:42 Pacific
Subject: PHP Script and HTML Forms
Reply: (edit)

It seems all that you are trying to do is get a picture from the user to add to the record of user information. All you really need to do is to combine the PHP scripts into one PHP script and the HTML forms into one HTML form and have the action pointing to the one PHP script. I do not see a reason why you want to split the Forms when you can combine them into one... just have the picture upload piggyback on your user information submit process. By the way, if you are the same guy that posted this in the PHP forum, i sent the code over last night.

Infinite Recursion


Report Offensive Follow Up For Removal

Response Number 3
Name: pymphar
Date: August 25, 2003 at 08:42:47 Pacific
Subject: PHP Script and HTML Forms
Reply: (edit)

Thnx for suggestions. I now have one HTML file with one PHP script to process the results. Infinite Recursion, your code that you posted on the PHP forum worked great. Thnx again.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: PHP Script and HTML Forms

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge