PHP Submission form problems - NEED HELP, URGENTLY

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

davelevin777
Forum Newbie
Posts: 10
Joined: Thu Mar 13, 2008 5:06 am

PHP Submission form problems - NEED HELP, URGENTLY

Post by davelevin777 »

Hi,

I am new to this forum and have several problems with a form that I am trying to build for a web directory.

My biggest problem is that when trying to send a PHP command's result through the form, it doesn't get sent.

EXPLANATION:

My directory will have about 2000 categories (pages) and I am building a listing submission form for it. My form is ready (HTML, PHP elements in it) and works fine except the PHP script in it...

Because there are so many categories, I am using this PHP scrip to display the previous page (category):

Submit to category (website address):
<?php
echo $_SERVER['HTTP_REFERER'];
?>


The user goes into the category, then to the submission page, which remembers the URL and displays it.

This PHP script is inside my form (between <form> and </form>).
But the displayed previous URL doesn't get sent by the form!

:(

What could I do, how can I send it?

Please, if someone can help me, I will be very thankful! :o

Dave
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by seodevhead »

Post your form html and the php that handles the exact $_POST that is associated with that referrer value.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by RobertGonzalez »

Moved to PHP - Code.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by RobertGonzalez »

Not all servers set the HTTP_REFERER property. You should not rely on it at all.
davelevin777
Forum Newbie
Posts: 10
Joined: Thu Mar 13, 2008 5:06 am

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by davelevin777 »

Everah | Please use the appropriate bbCode tags when posting code in the forms. You can use [code], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight as.

Everah | Please do not post that your problem is urgent. All problems around here are urgent and the folks that volunteer their time here to help you will get to your problem as soon as they can

Hello,

I managed to solve the problem alone with a simple "hidden" command... now that part works

But I have another problem. And this problem really seems to be without any explanation!

The problem: my form doesn't send my TEXTAREA content to my e-mail.

--------------------------------------------------------------------------------------------
Here is my form script:

Code: Select all

<form method="post" action="thankyou1.php">
 
<p>
Submit to category (web address): 
<?php
echo $_SERVER['HTTP_REFERER'];
?>
 
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
?>
<input type="hidden" name="client's ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="category" value="<?php echo $httprefi ?>" />
<br>
</br>
<p>
Your full name:
<p>
<input type="text" name="submitter's name" size="64" maxlength="40">
<p>
Your e-mail address:
<p>
<input type="text" name="e-mail" size="64" maxlength="40">
<p>
Your e-mail address again:
<p>
<input type="text" name="e-mail again" size="64" maxlength="40">
<p>
 
<p>
Listing title:
<p>
<input type="text" name="listing title" size="64" maxlength="40">
<p>
Listing description:
<p>
<textarea cols="64" rows="4" wrap="hard"></textarea>
<p>
URL:
<p>
<input type="text" name="URL" size="64" maxlength="40">
</p> 
<input type="submit" name="submit" value="Submit request">
<input type="reset" value="Reset all fields">
</form>
------------------------------------------------------------------------------------------

OK and, the form uses a "thank you" page. A "thank you" message appears after submission.
This "thank you" page is PHP, it contains the e-mail address and other elements necessary for me to receive the e-mail

Here is the code of my "thank you" page:

Code: Select all

<script language="php">
$email = $HTTP_POST_VARS[email];
$mailto = "[b]MYEMAIL[/b]";
$mailsubj = "Flux Travel LISTING SUBMISSION";
$mailhead = "From: Flux Travel Submission System";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
</script>
 

So, it works fine.... but the TEXTAREA is not sent... :(

What could I do?

I tried everything I that came into my mind and I still find the whole coding perfectly in order...


Everah | Please use the appropriate bbCode tags when posting code in the forms. You can use [code], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight as.
Last edited by RobertGonzalez on Thu Mar 13, 2008 12:13 pm, edited 1 time in total.
Reason: Tags note added, urgency note added
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by RobertGonzalez »

PHP cannot be called like you have it in the second snippet. And your form field names are little odd. Perhaps something like this might work (note, your code did not have a name for the textarea field so PHP would have never know what the value of the textarea was):

Code: Select all

<?php
if ($_SERVER['REQUEST_METHOD' == 'POST') {
    $email = $_POST['email'];
    $mailto = "me@mymail.com";
    $mailsubj = "Flux Travel LISTING SUBMISSION";
    $mailhead = "From: Flux Travel Submission System";
    $mailbody = "Values submitted from web site form:\n";
    
    foreach ($_POST as $key => $value) {
        $mailbody .= $key . ': ' . $value . "\n";
    }
    
    if (! mail($mailto, $mailsubj, $mailbody, $mailhead)) {
        die('Could not send the message.');
    }
    
    echo '<p>Thanks for sending the following message:</p>';
    echo nl2br($mailbody);
} else {
    $clientip = getenv("REMOTE_ADDR");
    $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
?>
<form method="post" action="<?php echo basename(__FILE__); ?>">
<input type="hidden" name="clientip" value="<?php echo $clientip; ?>" />
<input type="hidden" name="category" value="<?php echo $referer; ?>" />
<p>Your full name:</p>
<p><input type="text" name="name" size="64" maxlength="40"></p>
<p>Your e-mail address:</p>
<p><input type="text" name="email" size="64" maxlength="40"></p>
<p>Your e-mail address again:</p>
<p><input type="text" name="emailagain" size="64" maxlength="40"></p>
 <p>Listing title:</p>
<p><input type="text" name="listingtitle" size="64" maxlength="40"></p>
<p>Listing description:</p>
<p><textarea cols="64" rows="4" wrap="hard" name="description"></textarea></p>
<p>URL:</p>
<p><input type="text" name="URL" size="64" maxlength="40"></p>
</p><input type="submit" name="submit" value="Submit request"><input type="reset" value="Reset all fields"></p>
</form>
<?php
}
?>
davelevin777
Forum Newbie
Posts: 10
Joined: Thu Mar 13, 2008 5:06 am

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by davelevin777 »

Hello,

Thank you, I am checking it now...

But I think you made some errors in the first part of the script, because much of the text appears on the site (visible). So I find the first part unusable...

My names are odd because I need comprehensive descriptions in my inbox, as easy to understand as possible.

Thanks for helping, I still have a list of bugs, problems...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by RobertGonzalez »

You're right, I had a small error. it is fixed here. As for the descriptive names, try mapping them in another array. Having form field names with spaces and apostrophes in them could cause problems when reading them later.

Code: Select all

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $email = $_POST['email'];
    $mailto = "me@mymail.com";
    $mailsubj = "Flux Travel LISTING SUBMISSION";
    $mailhead = "From: Flux Travel Submission System";
    $mailbody = "Values submitted from web site form:\n";
    
    foreach ($_POST as $key => $value) {
        $mailbody .= $key . ': ' . $value . "\n";
    }
    
    if (! mail($mailto, $mailsubj, $mailbody, $mailhead)) {
        die('Could not send the message.');
    }
    
    echo '<p>Thanks for sending the following message:</p>';
    echo nl2br($mailbody);
} else {
    $clientip = getenv("REMOTE_ADDR");
    $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
?>
<form method="post" action="<?php echo basename(__FILE__); ?>">
<input type="hidden" name="clientip" value="<?php echo $clientip; ?>" />
<input type="hidden" name="category" value="<?php echo $referer; ?>" />
<p>Your full name:</p>
<p><input type="text" name="name" size="64" maxlength="40"></p>
<p>Your e-mail address:</p>
<p><input type="text" name="email" size="64" maxlength="40"></p>
<p>Your e-mail address again:</p>
<p><input type="text" name="emailagain" size="64" maxlength="40"></p>
 <p>Listing title:</p>
<p><input type="text" name="listingtitle" size="64" maxlength="40"></p>
<p>Listing description:</p>
<p><textarea cols="64" rows="4" wrap="hard" name="description"></textarea></p>
<p>URL:</p>
<p><input type="text" name="URL" size="64" maxlength="40"></p>
</p><input type="submit" name="submit" value="Submit request"><input type="reset" value="Reset all fields"></p>
</form>
<?php
}
?>
davelevin777
Forum Newbie
Posts: 10
Joined: Thu Mar 13, 2008 5:06 am

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by davelevin777 »

Hello,

Thanks, I will try this out & get back...
I am having difficulties with validations.

Regards,

Dave
davelevin777
Forum Newbie
Posts: 10
Joined: Thu Mar 13, 2008 5:06 am

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by davelevin777 »

Dear Everah,

I have a more problems. I appreciate your help, you are friendly...

But when I put this code in:

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = $_POST['email'];
$mailto = "me@mymail.com";
$mailsubj = "Flux Travel LISTING SUBMISSION";
$mailhead = "From: Flux Travel Submission System";
$mailbody = "Values submitted from web site form:\n";

foreach ($_POST as $key => $value) {
$mailbody .= $key . ': ' . $value . "\n";
}

if (! mail($mailto, $mailsubj, $mailbody, $mailhead)) {
die('Could not send the message.');
}

echo '<p>Thanks for sending the following message:</p>';
echo nl2br($mailbody);
} else {
$clientip = getenv("REMOTE_ADDR");
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
?>


Then much of it appears in the page (visible).
I also use Frontpage and Notepad for creating PHP files.

The code above I have put into a clear (no other code) new PHP file "thankyou.htm"

And this appears as visible...

$value) { $mailbody .= $key . ': ' . $value . "\n"; } if (! mail($mailto, $mailsubj, $mailbody, $mailhead)) { die('Could not send the message.'); } echo '
Thanks for sending the following message:

'; echo nl2br($mailbody); } else { $clientip = getenv("REMOTE_ADDR"); $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; ?>


So, I think there are more errors in it, but I just cannot understand why...

But, if I use the tags:

<script language="php">
</script>


Instead of:

<?php
?>


Then it doesn't appear...

I don't know why I cannot use the standard <?php> normally...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by RobertGonzalez »

PHP cannot be run on the client (like javascript is) so I am not sure what is happening with you code. As far as it throwing errors I justed tested it as is and I am getting no errors in it so I really have no idea what is happening on your server.

As a side note, rather than changing the color of the code text you are posting, can you use either the [code] bbCode tag or the [php] tag around code you post in the forums? It helps everyone read your post better.
davelevin777
Forum Newbie
Posts: 10
Joined: Thu Mar 13, 2008 5:06 am

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by davelevin777 »

Hello,

Everah, you have made some significant changes in my script, it looks very different now, but works exactly the same way...
What is the difference (functionally)?

Earlier I was given this reply...
seodevhead wrote:Not all servers set the HTTP_REFERER property. You should not rely on it at all.
In fact I am relying on it completely... Tested it in all 5 major browsers, works fine.
Do you think there is some risk for some clients... Like, could they not see the REFERER work?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by RobertGonzalez »

Referer is not a browser thing (I believe). I think it is set by the server. Not all servers set it so you should not rely on it.

And I didn't change the code at all from the last time I posted.
davelevin777
Forum Newbie
Posts: 10
Joined: Thu Mar 13, 2008 5:06 am

Re: PHP Submission form problems - NEED HELP, URGENTLY

Post by davelevin777 »

If you are referring at the server on which my site is hosted, it is OK. It functions now.
I believe it will always work.

I meant, you modified the code when you first posed it, not the second time.

I will get back with some questions, because I am getting tied up in the validation thing...
davelevin777
Forum Newbie
Posts: 10
Joined: Thu Mar 13, 2008 5:06 am

Other problems...

Post by davelevin777 »

Hello,

Here I am with the next problem: my form validation script doesn't work correctly...
The problem is: it only validates the first few (2 or 3, I'm not sure) fields...
So if you fill out those first fields, it verifies...
But if you leave all the rest unfilled, the script doesn't even see it. You can click "SUBMIT" and it will go through... So I receive partial information...

Here is the validation script:

Code: Select all

<script type="text/javascript">
 
function handleEnter (field, event) {
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
        if (keyCode == 13) {
            var i;
            for (i = 0; i < field.form.elements.length; i++)
                if (field == field.form.elements[i])
                    break;
            i = (i + 1) % field.form.elements.length;
            field.form.elements[i].focus();
            return false;
        } 
        else
        return true;
    }      
 
</script>
The form script is the same as the one I posted way above...

This script is actually Javascript. I use it combined with the rest of the form because it is easier than PHP and this validation script in particular looks great...

Don't know what is wrong...
Post Reply