launching php file from button not link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aerris
Forum Newbie
Posts: 5
Joined: Sun Feb 01, 2004 5:31 pm

launching php file from button not link

Post by aerris »

Hi... any help much appreciated!
I have created a file called addvenue.php with the following if condition at the start of it:

Code: Select all

<?php 
 if (isset($_GET['addvenue'])): // If the user wants to add a venue
?> 
<form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
<p>Venue Name<br /> 
<input type="text" name="vname" SIZE="40"><br /><BR>
<input type="submit" name="submitvenue" value="SUBMIT" /> 
</p> 
</form>  

<?php 
 else: // Default page display
in the default page display is a link that will reload the page making the if condition true, showing the submission form.

I can make the link work with a word:

Code: Select all

echo('<BR><a href="' . $_SERVER['PHP_SELF'] . 
      '?addvenue=1">Add a venue!</a><BR>');
But i really want it to be a button. I can make other button links such as:

Code: Select all

echo('<FORM METHOD="LINK" ACTION="addvenue.php">
<INPUT TYPE="submit" VALUE="Refresh Page"></FORM>');
That basically refreshes the page. Can i make a button link for the if condition too? I tried this:

Code: Select all

echo('<BR>
<FORM METHOD="LINK" ACTION="' . $_SERVER['PHP_SELF'] .'?addvenue=1"><INPUT TYPE="submit" VALUE="Add Venue">');
but it only reloads the same page...

anyone know why this is happening or how else i could do it? Am i going about this the wrong way?

thanks
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

form method="get"
User avatar
aerris
Forum Newbie
Posts: 5
Joined: Sun Feb 01, 2004 5:31 pm

ok

Post by aerris »

I tried:

Code: Select all

echo('<BR> 
<FORM METHOD="get" ACTION="' . $_SERVER['PHP_SELF'] .'?addvenue=1"><INPUT TYPE="submit" VALUE="Add Venue">');
but it still only reloads the page without running the if statement
:S
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="hidden" name="addvenue" value="true">
<input type="submit" value="Submit">
</form>
jaxn
Forum Commoner
Posts: 55
Joined: Fri Jan 16, 2004 1:50 pm
Location: Nashville, TN

Post by jaxn »

You can do the hidden field (that works perfectly well), however you can also just use the post for method and put the condition in the form action:

Code: Select all

echo('&lt;BR&gt; 
&lt;FORM METHOD="post" ACTION="' . $_SERVER&#1111;'PHP_SELF'] .'?addvenue=1"&gt;&lt;INPUT TYPE="submit" VALUE="Add Venue"&gt;');
-Jackson
User avatar
aerris
Forum Newbie
Posts: 5
Joined: Sun Feb 01, 2004 5:31 pm

:D

Post by aerris »

nice one cheers. :D
Post Reply