...

View Full Version : form action using a GET



ramenraider
02-01-2012, 10:48 PM
index.php


switch ($_GET['page'])
{
case "home":
include ('pages/home.php');
break;
case "search":
include ('pages/search.php');
break;
}

the form

<form method="post" action="<? echo $domain; ?>?page=search">
<input type="text" class="search_bar" name="s" />
<input type="submit" value="submit" />
</form>

search.php

search( $_GET['key'] ) ;



First I'd like to add that I know the switch statement works, I know the search function works and the form does pass the GET variable if I set the action of the form to the direct php page.

If I try to set the action to the ?page=search it doesn't pass the variables correctly even though I thought this was alright to do. I'd appreciate any help! This has been irritating me all day.

mlseim
02-01-2012, 10:56 PM
Not a good idea to mix POST with GET

Your form has the method defined as "post", so do it like this instead.


<form method="post" action="<? echo $domain; ?>">
<input type="hidden" name="page" value="search">
<input type="text" class="search_bar" name="s" />
<input type="submit" value="submit" />
</form>


$page=$_POST['page'];
$search=$_POST['s'];
echo "You are searching $page for $search";

You'll like using POST because the URL won't have any variables showing in it.

$_GET is used for seeing the variables in a URL.
$_POST is most commonly used for submitted forms.
(although forms can use $_GET ... but not very useful)


.

ramenraider
02-02-2012, 01:24 AM
Not a good idea to mix POST with GET

Your form has the method defined as "post", so do it like this instead.


<form method="post" action="<? echo $domain; ?>">
<input type="hidden" name="page" value="search">
<input type="text" class="search_bar" name="s" />
<input type="submit" value="submit" />
</form>


$page=$_POST['page'];
$search=$_POST['s'];
echo "You are searching $page for $search";

You'll like using POST because the URL won't have any variables showing in it.

$_GET is used for seeing the variables in a URL.
$_POST is most commonly used for submitted forms.
(although forms can use $_GET ... but not very useful)


.

Well my index.php is setup so that all my pages are modular. The switch statement actually has a ton more stuff in it, I just didn't want to include every case for the sake of space.

I can find work arounds such as the method you posted, but I'd rather just do it in a more straight forward fashion. I thought I'd read that you can do it like I'm doing it, I just can't figure out what the problem is.

Wanna
02-02-2012, 09:06 AM
You can do two things:

Change this code

search( $_GET['key'] ) ;
to

search( $_POST['key'] ) ;

or this:

<form method="post" action="<? echo $domain; ?>?page=search">
<input type="text" class="search_bar" name="s" />
<input type="submit" value="submit" />
</form>
to

<form method="get" action="<? echo $domain; ?>?page=search">
<input type="text" class="search_bar" name="s" />
<input type="submit" value="submit" />
</form>

BluePanther
02-02-2012, 10:00 AM
Well my index.php is setup so that all my pages are modular. The switch statement actually has a ton more stuff in it, I just didn't want to include every case for the sake of space.

I can find work arounds such as the method you posted, but I'd rather just do it in a more straight forward fashion. I thought I'd read that you can do it like I'm doing it, I just can't figure out what the problem is.

The method suggested by mlseim isn't a work around - it's the best solution. It is 'straight forward' because all you need to do is change $_GET['page'] to $_POST['search'] and use the hidden input.

Like msleim said, you're submitting the form using POST - the browser will send the values in the header as POST. So, passing all your information like this makes the most logical sense.

mlseim
02-02-2012, 12:21 PM
Is what you're doing an actual "search"?

You're searching for some string on a page?

Or, is what you're doing a way of controlling the content on a page?

Describe what you're doing.

RJGonzalez
02-10-2012, 08:59 PM
I have a question about forms, I have one that by a script sends email, fname, lname & phone and sends the data to my email marketing program the problem is that I also need the form to post all the data to an email.

is there a way to have two actions and 2 methods?

example here:

method="post|get" action="/form.php?form=5|email@address.com"

mlseim
02-10-2012, 09:54 PM
One PHP script does both in the same script.

Send the email first, then do the marketing program thing.

If I'm understanding you correctly, you have some sort of
email marketing program that uses GET instead of POST?

Or, what is your question?

Show us your actual form, and also
show us your "form.php" script.

RJGonzalez
02-10-2012, 10:30 PM
The other way around, I have an email marketing program that I am creating a call script for employees to fill in when a prospect call the office to create an appointment.

After is filled the data goes into a list, the email notification I am getting is only the email address, and I need it to send all data collected.

Thank you fro your prompt response, and sorry that I'm use to wait for hours on other forums, I'll pay attention this time :)

mlseim
02-10-2012, 11:19 PM
Well, as I said ...
Post the form they are filling out,
and post the script you wrote that only sends the email address.

This sounds like it should be a mobile online app, where you can
punch a button and get an instant list of details for ALL forms
that were submitted. Perhaps there doesn't need to be an email at all ...
or in the least, you are notified to check the data.

One problems with emails ... let's say a prospect creates an appointment
and your employee fills out the form, and you get an email with the details.
An hour later, the prospect calls and says "something just came up and I
need to reschedule". What then? So your employee fills it out again and you
get another email? What if you didn't see the 2nd email?

Wouldn't it be much better if the employee entered the appointment into a
database, and they update it for any changes? At any time, you click an icon on
your iphone, and instantly you access the database of appointments. Scroll
through, sort by date, time, filter results. Even get an instant SMS message
to remind you of upcoming appointments or changes.

I always think email is a bad idea for informational applications.
But it can be done. It's your company ... you can do whatever you want.

RJGonzalez
02-11-2012, 12:02 AM
You open my eyes, I will start working on something more practical with your ideas, thank you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum