submit multiple updates at once.

General discussions related to php

Moderators: macek, egami, gesf

ckwall

submit multiple updates at once.

Postby ckwall » Mon Jan 27, 2003 8:59 pm

I have the following page built. Can I create one last update button that will run all of the update buttons?

<html>

<FORM NAME="fa" ACTION="spences_corner.php" METHOD="POST">
<B>Spences Corner:</B><br>
<TEXTAREA NAME="Spences_Corner" ROWS=5 COLS=40></TEXTAREA>
<INPUT TYPE="submit" VALUE="Update">
</FORM>

<FORM NAME="fa" ACTION="today_in_lex.php" METHOD="POST">
<br><B>Today in Lex:</B><br>
<TEXTAREA NAME="Today_in_Lex" ROWS=5 COLS=40></TEXTAREA>
<INPUT TYPE="submit" VALUE="Update">
</FORM>

<FORM NAME="fa" ACTION="general_announcements.php" METHOD="POST">
<br><B>General Announcements:</B><br>
<TEXTAREA NAME="General_Announcements" ROWS=5 COLS=40></TEXTAREA>
<INPUT TYPE="submit" VALUE="Update">
</FORM>

</html>

TheIceman5
New php-forum User
New php-forum User
Posts: 28
Joined: Tue Jan 21, 2003 9:31 pm
Contact:

Postby TheIceman5 » Tue Jan 28, 2003 12:14 am

to begin with you will have to rename them forms, you cant have 3 forms with the same name if you want to update the 3 at once.
Just use a function that has 3 submits in it called by your last button.
Just noticed the forms are submitting to 3 different pages, why? what happens after you press update button? does code run that updates a database or something? if so why dont you just use 1 script for that.

ckwall

Postby ckwall » Tue Jan 28, 2003 7:28 am

These are all going to different locations of a company intranet. I guess I could use a database, but I have not learned how to do this yet. These each are going to a text file and then added to the intranet site as server side included files.

Let me try out your suggestion real quick. Thanks.

ckwall

Postby ckwall » Tue Jan 28, 2003 7:32 am

OK, I am lost. How to I set the function up with multiple submits? How does it specify what it is updating?

Maybe provide an example.

TheIceman5
New php-forum User
New php-forum User
Posts: 28
Joined: Tue Jan 21, 2003 9:31 pm
Contact:

Postby TheIceman5 » Thu Jan 30, 2003 1:15 am

well im lost at what your trying to acheive here, it seems you are going about this thing very difficultly. If you press the first update button it calls spences_corner.php, what does this do from here? theres no actions specified anywhere.

go have a read of this tutorial on MySQL databses and forms, its a pretty good tut for beginners, tells you everything step by step in detail.
http://hotwired.lycos.com/webmonkey/pro ... rial4.html

ckwall

Postby ckwall » Thu Jan 30, 2003 7:37 pm

Actualy what this is doing is sening the text in the text field to a text file. I do not have the luxury of using mysql. It is not supported by the server I am hosting on.

I have learned however that I should have writen these scripts differently. Using else. I cannot figure out the right way to do that.

These three fields are use individualy by people in my office to update a portion of an intranet site. I would just do one update, but unless all three boxes have text, the empty boxes over-write the text that should be there. So I need to have a script that does something to the effect that if there is text in the box, update, then move on to the next box and do the same, but if there is no text in the box, do not update it. then move on to the next and do the same.

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Fri Jan 31, 2003 2:18 am

I agree with iceman when he says rename the form name
ex

<FORM NAME="fa" ACTION="spences_corner.php" METHOD="POST"> would be <FORM NAME="spencers_corner" ACTION="spences_corner.php" METHOD="POST">

<FORM NAME="fa" ACTION="today_in_lex.php" METHOD="POST"> would be <FORM NAME="today_in_lex" ACTION="today_in_lex.php" METHOD="POST">

and

<FORM NAME="fa" ACTION="general_announcements.php" METHOD="POST"> would be <FORM NAME="general_announcements" ACTION="general_announcements.php" METHOD="POST">

ckwall

Postby ckwall » Fri Jan 31, 2003 7:21 am

OK, I have made that change. Now how do I call all three forms to update?

<html>

<FORM NAME="spences_corner" ACTION="spences_corner.php" METHOD="POST">
<B>Spences Corner:</B><br>
<TEXTAREA NAME="Spences_Corner" ROWS=5 COLS=40></TEXTAREA>
<INPUT TYPE="submit" VALUE="Update">
</FORM>

<FORM NAME="today_in_lex" ACTION="today_in_lex.php" METHOD="POST">
<br><B>Today in Lex:</B><br>
<TEXTAREA NAME="Today_in_Lex" ROWS=5 COLS=40></TEXTAREA>
<INPUT TYPE="submit" VALUE="Update">
</FORM>

<FORM NAME="general_announcements" ACTION="general_announcements.php" METHOD="POST">
<br><B>General Announcements:</B><br>
<TEXTAREA NAME="General_Announcements" ROWS=5 COLS=40></TEXTAREA>
<INPUT TYPE="submit" VALUE="Update">
</FORM>

</html>

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Sun Feb 02, 2003 12:47 am

why 3?
you can do this by 1 form =)

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Mon Feb 03, 2003 7:05 am

Hi!
Maby the best if you collect from page all info in variable and in next page simply send at pages all info?

ckwall

Postby ckwall » Mon Feb 03, 2003 8:47 am

Ok, i see what you are all saying. I just dont know how to do it. Can someone walk me through this or provide an example. This is the first script that I have ever written, I honestly dont know how i did it.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Mon Feb 03, 2003 10:56 am

One form, one action, three fields sent...

<form action="update_files.php" method="post">
<B>Spences Corner:</B><br>
<TEXTAREA NAME="Spences_Corner" ROWS=5 COLS=40></TEXTAREA>
<br><B>Today in Lex:</B><br>
<TEXTAREA NAME="Today_in_Lex" ROWS=5 COLS=40></TEXTAREA>
<br><B>General Announcements:</B><br>
<TEXTAREA NAME="General_Announcements" ROWS=5 COLS=40></TEXTAREA>
<INPUT TYPE="submit" VALUE="Update">
<input type="submit" value="update filled fields" />
</form>

update_files.php
----------------
if(isset($_POST['Spences_Corner']) && $_POST['Spences_Corner'] !== "")
{
// spences corner textarea filled - process
$f = fopen('spences.txt',"w");
fwrite($f,$_POST['Spences_Corner']);
fclose($ff);
}

if(isset($_POST['Today_in_Lex']
etc etc

---------------------

You could get away with iterating the _POST array if the file names reflected the form field names - gets a lil more complicated though, so might be best to hardcode each process for the time being.

ckwall

Postby ckwall » Mon Feb 03, 2003 4:10 pm

So if I understand the update_files.php correctly, this will only update if there is text entered into the box, correct? I would then do an entry for each field just like the one in the example. Right?


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests

cron