Connecting Tech Pros Worldwide Help | Site Map

Form not working when called through Include

Greg A
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi:

I have my index.php page.

For the header, sidebar, and footer, those are separate php pages that I
call into the index.php page.

My sidebar.php page has a form in it, that works fine if I load the page by
itself. However when I try to use it in the index.php page being called by
an include, it doesn't work.

Is there a way to make it so it does work? I think there may be some way to
use $_GET to make this work, but I'm not quite sure how to implement it.

Thanks!

Here is my code just incase it's needed:

<?


$form_block = "
<TABLE border=1><TR><TD align=center>

<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">
<span class=\"textmessage\">
<strong>Send To:</strong><br>
<SELECT NAME=\"name_select\" class=\"textbox\">
<option value=\"1111111111 at messaging.nextel.com\">Greg </option>
<option value=\"1111111111 at messaging.nextel.com\">John</option>
<option value=\"1111111111 at messaging.nextel.com\">Fred</option>
</select>

<br>
<strong>Name:</strong><br>
<INPUT type=\"text\" class=\"textbox\" NAME=\"sender_name\" SIZE=18>
<br>
<strong>Message:</strong><br>

<TEXTAREA NAME=\"limitedtextarea\" class=\"textbox\" cols=15
onKeyDown=\"limitText(this.form.limitedtextarea,th is.form.countdown,100);\"
onKeyUp=\"limitText(this.form.limitedtextarea,this .form.countdown,100);\"[color=blue]
>[/color]
</TEXTAREA>
<span class=\"smallfont\">(Max Characters: 100)<br>
You have <input class=\"textbox\" readonly type=\"text\"
name=\"countdown\" size=1 value=\"100\">characters left.</span>

<INPUT type=\"hidden\" name=\"op\" value=\"ds\">
<INPUT TYPE=\"submit\" class=\"submit\" NAME=\"submit\" VALUE=\"Send
This Form\">

</span>
</FORM>

</TD></TR>
</TABLE>
";


if ($_POST['op'] != "ds") {
echo "$form_block";

} else if ($_POST['op'] == "ds") {
//check value of $_POST[sender_name]
if ($_POST['sender_name'] == "") {
$name_err = "<font color=red>Please enter your
name!</font><br>";
$send = "no";
}
//check value of $_POST[limitedtextarea]
if ($_POST['limitedtextarea'] == "") {
$message_err = "<font color=red>Please enter your
message!</font><br>";
$send = "no";
}
if ($send != "no") {
//it's okay to send, so build the mail

$msg = "Message: $_POST[limitedtextarea]\n\n";

$to = $_POST['name_select'];
$sender = $_POST['sender_name'];


$subject = "";
$mailheaders = "From: $sender
<text @ web.com>\n";
//send the mail
mail ($to, $subject, $msg, $mailheaders);
//display confirmation to user
echo "<p>Mail has been sent!</p>";
} else if ($send =="no") {
//print error messages
echo "$name_err";
echo "$message_err";
echo "$form_block";
}
}

?>


Micha³ Wo¼niak
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Form not working when called through Include


One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable Greg A's handwriting:
[color=blue]
> Hi:
>
> I have my index.php page.
>
> For the header, sidebar, and footer, those are separate php pages that
> I call into the index.php page.
>
> My sidebar.php page has a form in it, that works fine if I load the
> page by itself. However when I try to use it in the index.php page
> being called by an include, it doesn't work.
>
> Is there a way to make it so it does work? I think there may be some
> way to use $_GET to make this work, but I'm not quite sure how to
> implement it.
>
> Thanks!
>
> Here is my code just incase it's needed:
>
> <?
>
>
> $form_block = "
> <TABLE border=1><TR><TD align=center>
>
> <FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">[/color]

Something's fishy about the above line... If you want the form to send
the values to the same file that's the form in, you should use
$_SERVER['PHP_SELF'], unless of course you have register_globals set to
on in php.ini - which is NOT a good idea.
However, IF you have register_globals on, it SHOULD work. Could you post
what exactly happens - what page get's loaded upon submiting the form,
or that no page is loaded, or watever else actually happens? That could
help to track down the problem.
[color=blue]
> <snip>[/color]

Cheers
Mike
Alvaro G Vicario
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Form not working when called through Include


*** Greg A wrote/escribió (Tue, 26 Apr 2005 20:32:23 -0700):[color=blue]
> My sidebar.php page has a form in it, that works fine if I load the page by
> itself. However when I try to use it in the index.php page being called by
> an include, it doesn't work.[/color]

I cannot see any include in your sample code. However, if I'm to guess, I'd
say you aren't including the code itself but the result of executing it.


--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Greg A
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Form not working when called through Include



"Michal Wozniak" <mikiwoz_remove_this@yahoo_remove_this.co.uk> wrote in
message news:d4nat8$o3g$1@213-238-75-8.adsl.inetia.pl...[color=blue]
> One quick glance of an experienced eye allowed to understand the blurred
> and almost unreadable Greg A's handwriting:
>[color=green]
>> Hi:
>>
>> I have my index.php page.
>>
>> For the header, sidebar, and footer, those are separate php pages that
>> I call into the index.php page.
>>
>> My sidebar.php page has a form in it, that works fine if I load the
>> page by itself. However when I try to use it in the index.php page
>> being called by an include, it doesn't work.
>>
>> Is there a way to make it so it does work? I think there may be some
>> way to use $_GET to make this work, but I'm not quite sure how to
>> implement it.
>>
>> Thanks!
>>
>> Here is my code just incase it's needed:
>>
>> <?
>>
>>
>> $form_block = "
>> <TABLE border=1><TR><TD align=center>
>>
>> <FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">[/color]
>
> Something's fishy about the above line... If you want the form to send
> the values to the same file that's the form in, you should use
> $_SERVER['PHP_SELF'], unless of course you have register_globals set to
> on in php.ini - which is NOT a good idea.
> However, IF you have register_globals on, it SHOULD work. Could you post
> what exactly happens - what page get's loaded upon submiting the form,
> or that no page is loaded, or watever else actually happens? That could
> help to track down the problem.
>[color=green]
>> <snip>[/color]
>
> Cheers
> Mike[/color]


Hi:

Let me start off with the problem I was running into (which I should have
mentioned previously).

Well the error I'm getting is:

Http 405 - Resource not allowed
Internet Information Services.

(I'd rather use Apache, but I don't have a choice)

I saw this page which explained stuff about the error:
http://www.somacon.com/blog/page26.php

However, my settings seem to be fine. And as I mentioned, the sidebar.php
page processes fine if I load it by itself rather than in an include.

If I make the action a separate PHP file, rather than php_self, it also
works fine. But I don't want an entire new page to load. I just wanted the
page to stay where it is.

I looked into what you said, and my register global is set to off.

I tried changing the line to: <FORM METHOD=\"POST\"
ACTION=$_SERVER['$PHP_SELF']>
However when I do that, I get this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting
T_STRING or T_VARIABLE or T_NUM_STRING in C:\Inetpub\wwwroot\new\sidebar.php
on line 72

Still lost.....

I was also simply using <? include 'sidebar.php'; ?>, perhaps this needs to
be more elaborate?

Thanks!


Greg A
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Form not working when called through Include



"Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in
message news:3dh030t0j69e$.a4lxevzask4q$.dlg@40tude.net...[color=blue]
> *** Greg A wrote/escribió (Tue, 26 Apr 2005 20:32:23 -0700):[color=green]
>> My sidebar.php page has a form in it, that works fine if I load the page
>> by
>> itself. However when I try to use it in the index.php page being called
>> by
>> an include, it doesn't work.[/color]
>
> I cannot see any include in your sample code. However, if I'm to guess,
> I'd
> say you aren't including the code itself but the result of executing it.
>
>
> --
> -- Álvaro G. Vicario - Burgos, Spain
> -- http://bits.demogracia.com - Mi sitio sobre programación web
> -- Don't e-mail me your questions, post them to the group
> --[/color]

Alvaro:

Hi, thanks for the response. I was using: <? include 'sidebar.php'; ?>

Should I be using this a little differently? I made another response up
above of the exact problem I am having. The form loads fine and looks good,
just the problem when I submit it.

Thanks!

-Greg



Micha³ Wo¼niak
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Form not working when called through Include


One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable Greg A's handwriting:
[color=blue]
> Hi:
>
> Let me start off with the problem I was running into (which I should
> have mentioned previously).
>
> Well the error I'm getting is:
>
> Http 405 - Resource not allowed
> Internet Information Services.
>
> (I'd rather use Apache, but I don't have a choice)
>
> I saw this page which explained stuff about the error:
> http://www.somacon.com/blog/page26.php
>
> However, my settings seem to be fine. And as I mentioned, the
> sidebar.php page processes fine if I load it by itself rather than in
> an include.
>
> If I make the action a separate PHP file, rather than php_self, it also
> works fine. But I don't want an entire new page to load. I just wanted
> the page to stay where it is.
>
> I looked into what you said, and my register global is set to off.[/color]

Well, here's your bug! :]
But...
[color=blue]
> I tried changing the line to: <FORM METHOD=\"POST\"
> ACTION=$_SERVER['$PHP_SELF']>
> However when I do that, I get this error:
>
> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
> expecting T_STRING or T_VARIABLE or T_NUM_STRING in
> C:\Inetpub\wwwroot\new\sidebar.php on line 72[/color]

Yes, because you forgot about the \"'s :)
<FORM METHOD=\"POST\"> ACTION=\"{$_SERVER['$PHP_SELF']}\">
this should work - at least it won't give you the parse error.
And it should definetely solve your problem, as far as I can see.

If not, you could also check, what is actually being written as an action
- try putting an
echo "Action is: " . $_SERVER['$PHP_SELF'];
somewhere in sidebar.php and check whether it is what you expect it to
be.
[color=blue]
> I was also simply using <? include 'sidebar.php'; ?>, perhaps this
> needs to be more elaborate?[/color]

No, that should be just fine.
[color=blue]
> Thanks![/color]

Cheers
Mike

Michael Brennan-White
Guest
 
Posts: n/a
#7: Jul 17 '05

re: Form not working when called through Include


Stupid Question but if you change the form action to get does the page
load? I am having problems with a page that will not load if I use a
post action but will work with a get action.

Greg A
Guest
 
Posts: n/a
#8: Jul 17 '05

re: Form not working when called through Include



"Michal Wozniak" <mikiwoz_remove_this@yahoo_remove_this.co.uk> wrote in
message news:d4nrdn$ies$1@213-238-75-8.adsl.inetia.pl...[color=blue]
> One quick glance of an experienced eye allowed to understand the blurred
> and almost unreadable Greg A's handwriting:
>[color=green]
>> Hi:
>>
>> Let me start off with the problem I was running into (which I should
>> have mentioned previously).
>>
>> Well the error I'm getting is:
>>
>> Http 405 - Resource not allowed
>> Internet Information Services.
>>
>> (I'd rather use Apache, but I don't have a choice)
>>
>> I saw this page which explained stuff about the error:
>> http://www.somacon.com/blog/page26.php
>>
>> However, my settings seem to be fine. And as I mentioned, the
>> sidebar.php page processes fine if I load it by itself rather than in
>> an include.
>>
>> If I make the action a separate PHP file, rather than php_self, it also
>> works fine. But I don't want an entire new page to load. I just wanted
>> the page to stay where it is.
>>
>> I looked into what you said, and my register global is set to off.[/color]
>
> Well, here's your bug! :]
> But...
>[color=green]
>> I tried changing the line to: <FORM METHOD=\"POST\"
>> ACTION=$_SERVER['$PHP_SELF']>
>> However when I do that, I get this error:
>>
>> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
>> expecting T_STRING or T_VARIABLE or T_NUM_STRING in
>> C:\Inetpub\wwwroot\new\sidebar.php on line 72[/color]
>
> Yes, because you forgot about the \"'s :)
> <FORM METHOD=\"POST\"> ACTION=\"{$_SERVER['$PHP_SELF']}\">
> this should work - at least it won't give you the parse error.
> And it should definetely solve your problem, as far as I can see.
>
> If not, you could also check, what is actually being written as an action
> - try putting an
> echo "Action is: " . $_SERVER['$PHP_SELF'];
> somewhere in sidebar.php and check whether it is what you expect it to
> be.
>[color=green]
>> I was also simply using <? include 'sidebar.php'; ?>, perhaps this
>> needs to be more elaborate?[/color]
>
> No, that should be just fine.
>[color=green]
>> Thanks![/color]
>
> Cheers
> Mike
>[/color]

This worked great. Thanks for your help, I appreciate it! =)


Micha³ Wo¼niak
Guest
 
Posts: n/a
#9: Jul 17 '05

re: Form not working when called through Include


One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable Greg A's handwriting:
[color=blue]
> This worked great. Thanks for your help, I appreciate it! =)[/color]

No problem, my pleasure. :)

Cheers
Mike

Closed Thread