Jump to content

Posting to URL


trp

Recommended Posts

Hey,

I am using some forms that post things to the URL (such as &update) for me to use within an 'if isset' statement.

The thing is I have one page with more than one form, each with different outputs, the first one adds to the url and any action after that also involves running the first request again.

Does anyone know a resolution for this?

 

Thanks,

 

TRP

Link to comment
Share on other sites

I'll show you the code  :shy:

 

				echo	"<tr>";
			echo		"<td align=center colspan=2>
							<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}&$actionone\">
							<input type=\"submit\" value = \"$actionone\">
							</form>
						</td>
						<td></td>";
			echo	"</tr>";
			echo	"<tr>";
			echo		"<td align=center colspan=2>
							<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}&$actiontwo\">
							<input type=\"submit\" value = \"$actiontwo\">
							</form>
						</td>
						<td></td>";
			echo	"</tr>";
			echo	"<tr>";
			echo		"<td align=center colspan=2>
							<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}&$actionthree\">
							<input type=\"submit\" value = \"$actionthree\">
							</form>
						</td>
						<td></td>";
			echo	"</tr>";

 

Then picked up by annother query using if isset, but as the url can easily look like &whatever&something it will do both..

Link to comment
Share on other sites

name your submit buttons

<input type="submit" name="submit_form" value="submit1"/>
<input type="submit" name="submit_form" value="submit2"/>
<input type="submit" name="submit_form" value="submit3"/>

 

and in the code that checks if a form submitted

if(isset($_POST['submit_form'])){
  switch($_POST['submit_form']){
  case "submit1":
    // Do something when submit button 1 is pressed
    break;
  case "submit2":
    // Do something when submit button 2 is pressed
    break;
  case "submit3":
    // Do something when submit button 3 is pressed
    break;
  }
}

Link to comment
Share on other sites

Or you could do it the way that most likely you'll have.

<input type="submit" name="submit_form1" value="submit"/>
<input type="submit" name="submit_form2" value="submit"/>
<input type="submit" name="submit_form3" value="submit"/>

Notice how I changed the names of the button, instead of value as deanlearner.

 

Then to validate the forms..

<?php
if(isset($_POST['submit_form1'])) {
    //Content for form 1 will go here...
}
if(isset($_POST['submit_form2'])) {
    //Content for form 2 will go here...
}
if(isset($_POST['submit_form3'])) {
    //Content for form 3 will go here...
}

And so on. I don't like using switches when using multiple forms. I like it all grouped together.

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.