Jump to content

PHP Help - HTML Form .POST


SarahKallista

Recommended Posts

Hello! I have just uploaded my new from-scratch HTML site to my server. I have five HTML forms within my site that I need to connect to .php forms that are set to .POST, sending me an email with the form contents. I have made the .php files for only two of the forms, as I wanted to run tests before completing the rest of the code. When I try to submit the form, however, I get an error. Would someone be willing to go through my HTML and PHP code to see if it was a coding error or something I should bring up with my server administrators?

If that is able to get sorted out, I also have one more favor to ask. I cannot for the life of me understand the code to .POST radio button data and checkbox data that would submit through the form and show in the email. Any help with that is also GREATLY appreciated!

 

- - - - - - - - - - - - - - - Here is my HTML for one of the forms: - - - - - - - - - - - - - - -


                    <form action="banners_form.php" method="POST">
                        <div class="bannerform_left">
                            <label for="myName">Name*</label>
                            <input type="text" name="myName" id="myName" placeholder="First & Last Name" required="required">
                            <label for="myAddressLine1">Shipping Address*</label>
                            <input type="text" name="myAddressLine1" id="myAddressLine1" placeholder="Line 1" required="required">
                            <br>
                            <input type="text" name="myAddressLine2" id="myAddressLine2" placeholder="Line 2">
                            <input class="halfsize" type="text" name="myCity" id="myCity" placeholder="City" required="required">
                            <input class="halfsize" type="text" name="myState" id="myState" placeholder="State" required="required">
                            <input class="halfsize" type="text" name="myZip" id="myZip" placeholder="Zip Code" required="required">
                            <input class="halfsize" type="text" name="myCountry" id="myCountry" placeholder="Country">
                            
                            <input class="submitbutton" type="submit" id="mySubmit" value="SUBMIT">
                        </div><!--closes bannerform_left-->
                        <div class="bannerform_right">
                            <label for="myEmail">Email*</label>
                            <input type="text" name="myEmail" id="myEmail" placeholder="Email Address" required="required">
                            <label for="myBannerSize">Banner Size*</label>
                            <input type="text" name="myBannerSize" id="myBannerSize" placeholder="1x1" required="required">
                            <label for="myDesign">Design Preferences <br>(colors, text, layout, etc.)*</label>
                            <textarea name="myDesign" id="myDesign" rows="9" cols="32" required="required"></textarea>
                        </div><!--closes bannerform_right-->
                    </form>

 

- - - - - - - - - - - - - - - Here is my PHP for that form: - - - - - - - - - - - - - - -

<?php
$myName = $_POST['myName'];
$myEmail = $_POST['myEmail'];
$myAddressLine1 = $_POST['myAddressLine1'];
$myAddressLine2 = $_POST['myAddressLine2'];
$myCity = $_POST['myCity'];
$myState = $_POST['myState'];
$myZip = $_POST['myZip'];
$myCountry = $_POST['myCountry'];
$myBannerSize = $_POST['myBannerSize'];
$myDesign = $_POST['myDesign'];
$formcontent="Name: $myName \n Email: $myEmail \n Address: $myAddressLine1 \n $myAddressLine2 \n $myCity \n $myState \n $myZip \n $myCountry \n $myBannerSize \n Design: $myDesign";
$recipient = "[redacted]";
$subject = "BANNER ORDER FORM SUBMISSION";
$mailheader = "From: $myEmail \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! Your inquiry has been submitted! If you do not receive a response within the next few days, please contact me via email." . " -" . "<a href='index.html'>Return Home</a>";
?>

Edited by requinix
removing email address - please be more careful in the future
Link to comment
Share on other sites

Welcome to the forum

First off, just saying your getting an error doesn't help anyone. We do not have a crystal ball and cannot see your screen. You need to post the exact errors you get. Blindly using user supplied data makes you ripe for an injection attack. Do not create variables for nothing. With checkboxes, you need to use isset. If the box is not checked, nothing will be sent with the form. It would be better practice to have your form and the processing code in the same page. Php at the top, HTML at the bottom.

Edited by benanamen
Link to comment
Share on other sites

"Internal Server Error 

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log."

 

Sorry for the ambiguity. Above is what error comes up from the code that I showed within my server. I have very limited experience with form security, and the only code I had found to prevent against injection was unclear how to implement it. If I were to put the PHP code at the top, how should I target it in my HTML if I don't have a file name? I greatly appreciate your advice and understanding with a PHP newbie ?

I'm assuming maybe I should bring this up with my server to see what they suggest, in terms of the form not submitting at all (their live chat has been fairly reliable in the past). I just want to make sure I'm not running in circles trying to solve the wrong issue if it turns out to be something else entirely.

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.