Jump to content


help! multiple submit forms on one page.


7 replies to this topic

#1 influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 30 August 2006 - 04:31 PM

hey, heres my code:
<?php
if ($_POST['submit']) {
if ($_POST['submit']) {
echo"hello1";
exit;
}else{
echo"
<form name=\"form\" method=\"post\">
<input name=\"submit\" type=\"submit\" id=\"submit\" value=\"Submit\">
</form>";
exit;
}
}else{
echo"hello4
<form name=\"form\" method=\"post\">
<input name=\"submit\" type=\"submit\" id=\"submit\" value=\"Submit\">
</form>";
}
?>

What i want is that when you hit the first submit button (after entering the info into a form) it brings up the next form and another submit button.
Please help, I'm very stuck:o
thanks.
influct!

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 30 August 2006 - 04:44 PM

This would probably be easier to do with AJAX, or something. Look into some tutorials on that, mainly the responceText and AJAX handler functions (I just learned how to use some AJAX last night, and it's so awesome!).

By the way, no matter what, on that code you've posted, you'll always get the first if statement evalutated as true, the one echoing 'hello1'.
You would have to put hidden fields in your form to tell it which form it is, then have it act accordingly if you were to do this by PHP alone.
I would personally use AJAX since it just makes it look better and doesn't have to reload the page and such. ;)

#3 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 30 August 2006 - 04:54 PM

name them different submit buttons?

<input name=\"submit1\" type=\"submit\" id=\"submit\" value=\"Submit\">

<input name=\"submit2\" type=\"submit\" id=\"submit\" value=\"Submit\">


#4 danieldaniel

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male
  • Location:Columbus, Ohio
  • Interests:Skateboarding, Macs, BMX, Cocoa, PHP, CSS etc.

Posted 30 August 2006 - 04:56 PM

Couln't you just do this:
<?php
if (isset($_POST["submit"]))
{
echo "
Second Form here
<form action=\"\" method=\"POST\" />
Input fields here
<input type=\"submit\" name=\"submit2\" value=\"\" />
</form>";
}
elseif (isset($_POST["submit2"]))
{
echo "
Third Form Here
<form action=\"\" method=\"POST\" />
Input Fields
</form>";
}
else
{
echo "
First Form Here
<form action=\"\" method=\"POST\" />
Input fields
<input type=\"submit\" name=\"submit\" value=\"\" />
</form>";
}
?>
That should work if I understand what you mean.

edit - AH! Spatial beat me!

Edited by danieldaniel, 30 August 2006 - 04:57 PM.


#5 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 30 August 2006 - 06:59 PM

View Postdanieldaniel, on Aug 30 2006, 04:56 PM, said:

edit - AH! Spatial beat me!

lol yeah, but you did the entire code. I was being lazy. :)

#6 influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 31 August 2006 - 06:31 AM

thanks you guys:D Im going to try it now.

#7 Ruben K

    Cliff

  • Twodded Staff
  • PipPip
  • 438 posts

Posted 31 August 2006 - 06:48 AM

You should consider using forms and arrays.
An example from a multiple-tutorials submit form I made last week:

Make a common field named 'count[]'
<input type="hidden" name="count[]" value="" />
Each time you put that field, we add one to our count. Put this in all of the submit forms.

This way we can count how many thigns were submitted by doing:

$count = count( $_POST['count'] );
$_POST['count'] holds an array of data for each time the form field count[] appears.

Now this is what your form should look like:

Tutorial #1:<br />
<input type="text" name="title[]" /><br />
<input type="test" name="author[]" /><br />
<input type="hidden" name="count[]" value="" />
<br />


Tutorial #2:<br />
<input type="text" name="title[]" /><br />
<input type="test" name="author[]" /><br />
<input type="hidden" name="count[]" value="" />
<br />

Now to get all form data, we loop through our array:

$count = count( $_POST['count'] );
for( $i=0; $i < $count; $i++ )
{
	// get data for tutorial $i + 1
	$current_tutorial = $i + 1;
	$current_title = $_POST['title'][ $i ];
	$current_author = $_POST['author'][ $i ];
}

This is essentially what it should look like.

Edited by Ruben K, 31 August 2006 - 06:52 AM.


#8 influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 01 September 2006 - 10:14 AM

hey thats pretty neat, thanks:)
Thats great for when withdrawing thing from sql:D
Help is hugely appreciated:)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users