Need MUCHO MUCHO help with PHP script

Discussion in 'PHP' started by ICE_monky, Jun 12, 2010.

  1. #1
    I have a form page in html and I have a small php contact script which I downloaded. I've been trying to make up a php script for the form but everytime I try to it doesnt work. The form is here:

    http://dunpaintedfarm.com/test/myform/myform

    If someone can help me out I will be SOOOOO greatful. I've tried finding php tutorials but havent been able to get this to work. The following is the php script that I've sloppily pieced together:


    <?php

    // get posted data into local variables
    $EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
    $EmailTo = "myemail@address.com";
    $Name_First = Trim(stripslashes($_POST['Name_First']));
    $Name_Last = Trim(stripslashes($_POST['Name_Last']));
    $Phone_1 = Trim(stripslashes($_POST['Phone_1']));
    $Phone_2 = Trim(stripslashes($_POST['Phone_2']));
    $Phone_3 = Trim(stripslashes($_POST['Phone_3']));
    $Address_1 = Trim(stripslashes($_POST['Address_1']));
    $Address_2 = Trim(stripslashes($_POST['Address_2']));
    $City = Trim(stripslashes($_POST['City']));
    $State = Trim(stripslashes($_POST['State']));
    $Zip = Trim(stripslashes($_POST['Zip']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Scope = Trim(stripslashes($_POST['Scope']));

    // validation
    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (Trim($Name_First)=="") $validationOK=false;
    if (Trim($Name_Last)=="") $validationOK=false;
    if (Trim($Phone_1)=="") $validationOK=false;
    if (Trim($Phone_2)=="") $validationOK=false;
    if (Trim($Phone_3)=="") $validationOK=false;
    if (Trim($Address_1)=="") $validationOK=false;
    if (Trim($Address_2)=="") $validationOK=false;
    if (Trim($City)=="") $validationOK=false;
    if (Trim($State)=="") $validationOK=false;
    if (Trim($Zip)=="") $validationOK=false;
    if (Trim($Email)=="") $validationOK=false;
    if (Trim($Scope)=="") $validationOK=false;
    if (!$validationOK)

    {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=form.html\">";
    exit;
    }

    // prepare email body text
    $Body = "";

    $Body .= "Name_First ";
    $Body .= $Name_Last;
    $Body .= "\n";

    $Body .= "Name_Last ";
    $Body .= $Name_Last;
    $Body .= "\n";

    $Body .= "Phone_1,Phone_2,Phone_3";
    $Body .= $Phone;
    $Body .= "\n";

    $Body .= "Address_1";
    $Body .= $Address_1;
    $Body .= "\n";

    $Body .= "Address_2";
    $Body .= $Address_2;
    $Body .= "\n";

    $Body .= "City";
    $Body .= $City;
    $Body .= "\n";

    $Body .= "State";
    $Body .= $State;
    $Body .= "\n";

    $Body .= "Zip";
    $Body .= $Zip;
    $Body .= "\n";

    $Body .= "Email";
    $Body .= $Email;
    $Body .= "\n";

    $Body .= "Scope";
    $Body .= $Scope;
    $Body .= "\n";


    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

    // redirect to success page
    if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
    }
    else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=contact.html\">";
    }
    ?>
     
    ICE_monky, Jun 12, 2010 IP
  2. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Where did you downloaded it??
    May i have a look in that! :)
     
    roopajyothi, Jun 12, 2010 IP
  3. Chronomus

    Chronomus Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    In what way doesn't it work? No one can help you if you just paste a wall of code and just say "it doesn't work". It's unlikely that someone is going to beta-test your code for you, that's your job. ;) We can, however, help you with fixing a specific problem.
     
    Chronomus, Jun 13, 2010 IP
  4. ICE_monky

    ICE_monky Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What I did was download a simple contact form from http://www.tele-pro.co.uk/scripts/contact_form/ The contact script and form I downloaded works fine so i tried adding variables to the php script and had "myform" call to the script to collect the data. I figured that since the contact form calls to th escript and works fine id be able to add a couple variables to the script and have the form call to it and it should work but it doesnt. Im not sure how to explain it that well without pasting the all the code here.

    This is the form I need a script for http://dunpaintedfarm.com/test/myform/myform

    And this the existing contact form and script i have which Im trying to edit to work with the above form. http://dunpaintedfarm.com/test/form/form.php
     
    ICE_monky, Jun 13, 2010 IP
  5. Chronomus

    Chronomus Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    So what you're saying is that the form input variables don't get passed to the PHP script that emails the form data? That's because you need to change the name="" parameters in your HTML form to match the PHP script's $_POST variables. For example, for the first name textbox, you put the name parameter as element_2_1, but you'll need to change it to Name_First to match the script. Alternatively, you can also change the PHP script's $_POST variables. For example, instead of $_POST['Name_First'], you could put $_POST['element_2_1'].
     
    Chronomus, Jun 13, 2010 IP
  6. ICE_monky

    ICE_monky Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    @ Chronomus -- Thats what I've done. I did my best to make sure that all the name="" within the html form are the same as whats in the php script.
     
    ICE_monky, Jun 13, 2010 IP
  7. ICE_monky

    ICE_monky Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    if you want I can post the form code and the php code that I have. I dont kno is that will help or not.
     
    ICE_monky, Jun 13, 2010 IP
  8. Chronomus

    Chronomus Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Then why did you post a link to another form? -_-

    How can you expect people help you fix a problem if you give them code that is completely irrelevant to what your actual code is? I'm not a mind reader, I can't guess your real code!
     
    Chronomus, Jun 14, 2010 IP
  9. ICE_monky

    ICE_monky Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    @ Chronomus This link here http://dunpaintedfarm.com/test/myform/myform.html is the form that I am using for ppl to fill out. What I am having trouble with is the PHP code which collects all the information. Im not expecting you to read my mind. I am blantely stating what I am having issues with here. Im using the form to collect data but the php script which collects and emails me the data isnt working correctly. How else would you like for me to explain this to you?

    Lets try this. Here is the HTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Untitled Form</title>
    <link rel="stylesheet" type="text/css" href="view.css" media="all">
    <script type="text/javascript" src="view.js"></script>

    </head>
    <body id="main_body" >

    <img id="top" src="top.png" alt="">
    <div id="form_container">

    <h1><a>Quote Request Form</a></h1>

    <form id="form_200498" class="appnitro" method="post" action="conform.php">
    <div class="form_description">
    <h2>Quote request Form</h2>
    <p>Please fill out the following to request and estimate for your job. </p>
    </div>

    <ul >
    <li id="li_2" >
    <label class="description" for="element_2">Name </label>
    <span>
    <input id="element_2_1" name= "element_2_1" class="element text" maxlength="255" size="8" value=""/>
    <label>First</label>
    </span>
    <span>
    <input id="element_2_2" name= "element_2_2" class="element text" maxlength="255" size="14" value=""/>
    <label>Last</label>
    </span>
    </li>

    <li id="li_3" >
    <label class="description" for="element_3">Phone </label>
    <span>
    <input id="element_3_1" name="element_3_1" class="element text" size="3" maxlength="3" value="" type="text"> -
    <label for="element_3_1">(###)</label>
    </span>
    <span>
    <input id="element_3_2" name="element_3_2" class="element text" size="3" maxlength="3" value="" type="text"> -
    <label for="element_3_2">###</label>
    </span>
    <span>
    <input id="element_3_3" name="element_3_3" class="element text" size="4" maxlength="4" value="" type="text">
    <label for="element_3_3">####</label>
    </span>
    </li>

    <li id="li_4" >
    <label class="description" for="element_4">Address </label>
    <div>
    <input id="element_4_1" name="element_4_1" class="element text large" value="" type="text">
    <label for="element_4_1">Street Address</label>
    </div>
    <div>
    <input id="element_4_2" name="element_4_2" class="element text large" value="" type="text">
    <label for="element_4_2">Address Line 2</label>
    </div>
    <div class="left">
    <input id="element_4_3" name="element_4_3" class="element text medium" value="" type="text">
    <label for="element_4_3">City</label>
    </div>
    <div class="right">
    <input id="element_4_4" name="element_4_4" class="element text medium" value="" type="text">
    <label for="element_4_4">State / Province / Region</label>
    </div>
    <div class="left">
    <input id="element_4_5" name="element_4_5" class="element text medium" maxlength="15" value="" type="text">
    <label for="element_4_5">Postal / Zip Code</label>
    </div>
    </li>

    <li id="li_5" >
    <label class="description" for="element_5">Email </label>
    <div>
    <input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/>
    </div>
    </li>

    <li id="li_6" >
    <label class="description" for="element_6">What Type of Work do You Need?</label>
    <span>
    <input id="element_6_1" name="element_6" class="element radio" type="radio" value="1" />
    <label class="choice" for="element_6_1">New Installation</label>
    <input id="element_6_2" name="element_6" class="element radio" type="radio" value="2" />
    <label class="choice" for="element_6_2">Reconfiguration</label>
    <input id="element_6_3" name="element_6" class="element radio" type="radio" value="3" />
    <label class="choice" for="element_6_3">Delivery</label>
    <input id="element_6_4" name="element_6" class="element radio" type="radio" value="4" />
    <label class="choice" for="element_6_4">Storage</label>
    </span>
    </li>

    <li id="li_1" >
    <label class="description" for="element_1">Paragraph </label>
    <div>
    <textarea id="element_1" name="element_1" class="element textarea medium"></textarea>
    </div>
    </li>

    <li class="buttons">
    <input type="hidden" name="form_id" value="200498" />
    <input id="saveForm" class="button_text" type="submit" value="Submit" /><!-- name="submit" -->
    </li>
    </ul>
    </form>

    <div id="footer">

    </div>
    </div>
    <img id="bottom" src="bottom.png" alt="">
    </body>
    </html>



    And here is the PHP script:

    <?php
    // Website Contact Form Generator
    // http://www.tele-pro.co.uk/scripts/contact_form/
    // This script is free to use as long as you
    // retain the credit link

    // get posted data into local variables
    $EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
    $EmailTo = "sk8decq@yahoo.com";
    $element_2_1 = Trim(stripslashes($_POST['element_2_1']));
    $element_2_2 = Trim(stripslashes($_POST['element_2_2']));
    $element_3_1 = Trim(stripslashes($_POST['element_3_1']));
    $element_3_2 = Trim(stripslashes($_POST['element_3_2']));
    $element_3_3 = Trim(stripslashes($_POST['element_3_3']));
    $element_4_1 = Trim(stripslashes($_POST['element_4_1']));
    $element_4_2 = Trim(stripslashes($_POST['element_4_2']));
    $element_4_3 = Trim(stripslashes($_POST['element_4_3']));
    $element_4_4 = Trim(stripslashes($_POST['element_4_4']));
    $element_4_5= Trim(stripslashes($_POST['element_4_5']));
    $element_5 = Trim(stripslashes($_POST['element_5']));
    $element_1 = Trim(stripslashes($_POST['element_1']));

    // validation
    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (Trim($element_2_1)=="") $validationOK=false;
    if (Trim($element_2_2)=="") $validationOK=false;
    if (Trim($element_3_1)=="") $validationOK=false;
    if (Trim($element_3_2)=="") $validationOK=false;
    if (Trim($element_3_3)=="") $validationOK=false;
    if (Trim($element_4_1)=="") $validationOK=false;
    if (Trim($element_4_2)=="") $validationOK=false;
    if (Trim($element_4_3)=="") $validationOK=false;
    if (Trim($element_4_4)=="") $validationOK=false;
    if (Trim($element_4_5)=="") $validationOK=false;
    if (Trim($element_5)=="") $validationOK=false;
    if (Trim($element_1)=="") $validationOK=false;
    if (!$validationOK) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
    exit;
    }

    // prepare email body text
    $Body = "";

    $Body .= "First Name";
    $Body .= $element_2_1;
    $Body .= "\n";

    $Body .= "Last Name";
    $Body .= $element_2_2;
    $Body .= "\n";

    $Body .= "Email";
    $Body .= $element_5;
    $Body .= "\n";

    $Body .= "Phone:";
    $Body .= $element_3_1; $element_3_2; $element_3_3;
    $Body .= "\n";

    $Body .= "Address 1";
    $Body .= $element_4_1;
    $Body .= "\n";

    $Body .= "Address 2";
    $Body .= $element_4_2;
    $Body .= "\n";

    $Body .= "City";
    $Body .= $element_4_3;
    $Body .= "\n";

    $Body .= "State";
    $Body .= $element_4_4;
    $Body .= "\n";

    $Body .= "Zip";
    $Body .= $element_4_5;
    $Body .= "\n";

    $Body .= "Scope";
    $Body .= $element_1;
    $Body .= "\n";


    // send email
    $success = mail($EmailTo, "Quote Request From Site", $Body, "From: <$EmailFrom>");

    // redirect to success page
    if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
    }
    else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=contact.html\">";
    }
    ?>
     
    ICE_monky, Jun 14, 2010 IP
  10. Chronomus

    Chronomus Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Then why did you post a different PHP script in the first post? That just doesn't make any sense. :/ That would still require me to read your mind to find out what the actual code is (the one you just decided to post now). The next thing you still need to explain is how is it not working 'correctly'? There could be a million different ways it doesn't work correctly. Does it pass the validation? Does it send any email at all? Do the variables get included in the email properly?

    My best guess is that it's not actually sending any email as the mail() function isn't working as you're expecting it to, but I'm not going to formulate a reply then to find that's not what the problem actually is like last time without you verifying what the problem actually is. I know you're 'blatantly' stating that you're having issues, but you still haven't described what the exact issues are apart from that it's just 'not working', instead you're leaving me to guess what the issue is.

    There's a good article called "How To Ask Questions The Smart Way". I recommend you read the section of it about asking for help with code. catb.org/~esr/faqs/smart-questions.html#code
    Remember, I'm just trying to help you. You're lucky that you even got a response from anyone without being specific enough about your issue, and the only thing that has happened so far is wasting my time to be honest. :D
     
    Last edited: Jun 15, 2010
    Chronomus, Jun 15, 2010 IP
  11. ICE_monky

    ICE_monky Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    OK. so u've officially made yourself look like a prick who hasn't gotten any GOOD sex in quite some time. The very first thing I said was the following :



    Let me break that down for ya now.
    1. I stated that I have an html form which I need to collect information from.
    2. I stated that I have a php script which is not working properly, I.E. it needs to be debugged since I cannot find the the bug.
    3. I gave you a link to the form itself so if need be one can view the source and check to make sure that my input variables are correct.
    4. I posted the php script itself[/B]

    NOW. the responses that followed all had me stating the same thing which is that I have a form. I have a PHP script. The two are not working together the way they should even tho I have done used existing WORKING code and just added a few input variables to both the html form AND the php script so they match. HENCE me saying that I am having problems getting the script to email me the information from the form.

    Now one could assume by my very first post in creating this thread that I am a noob at php scripting and that I need someone to look over the form code AND the php code so see what I did wrong. One would also ask questions such as, "May I see your form and your code please". OH WAIT! roopajyothi DID ask me something along those lines.

    SO in conclusion, get your head outta your ass, stop expecting everyone else to think along the same lines, or even possess some knowledge they obviously dont have since they are making threads asking for help, such as me, and uh, I don't know, STOP putting ppl down because they may not have some sort of knowledge that you just might contain inside that thick, self indulged, head of yours that I'm going to assume by your responses to me, just sits in front of a computer all day and your closest friend is some WoW character. Whom lives on another continent.

    Now if you can look over my code and tell me what variable is wrong or why the script isn't collecting my form data and sending it to me then I would truly be greatful, but if all you can come up with after everything I just said is some way to return an insult to me then consider yourself a success in attempting to insult me, but a failure in actually succeeding.
     
    ICE_monky, Jun 16, 2010 IP
  12. Chronomus

    Chronomus Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I would very seriously reconsider the way you are representing yourself here. Acting this unprofessional in a forum with a professional landscape such as this won't get you very far, and will seriously damage your reputation. I'm just stating, if I were you, I would be seriously concerned.
    This is the point where you are continually seriously failing to understand the fundamental logical concept I'm putting forward to you. You claim that you have a script that needs to be debugged because you can't find the bug, but the logical point that you have completely failed to comprehend is that you have not stated what the bug is. You have not even began to describe this imaginary bug. I say imaginary because you have not even attempted to begin describing the nature of this bug, or even refer to it. The closest you have ever done to elaborate on or describe this bug is (and I quote you)
    The quotes above are in chronological order, and the last quote is the most information I have managed to pry out of you about this imaginary bug. All I know so far about this imaginary bug is that:
    • It's in the PHP script that collects and emails the data.
    That's a whole lot of information isn't it? Well it certainly is nowhere near enough for anyone to even begin searching for this bug. Why? Because of one simple reason: you have not stated what the bug is, instead you are playing a riddle. That's right, a riddle. A riddle where we have to try and guess what this bug is. I have one question for you that I want you to answer. Just one. How does one debug or fix a bug, if they are not told what this bug is?

    ..oh, hold on. What's this you just posted right now in your previous post?
    Well done! You honestly deserve a medal (and I'm not even being sarcastic). You have now officially described the nature of this bug: the email does not reach the destination! This is the first time in this thread you have ever done this, so there is no "hence" here actually. Please quote where else in this thread you have previously stated this, looking at the above 4 quotes I've compiled from you which were the only statements you've said about the bug before the statement you just gave now describing the nature of the bug. Oh and, please, don't even try to edit your posts.
    Ahem. Let me quote roopajyothi for you, since you haven't even done that.
    Nowhere in this quote does she ask to see your code. She asks where you downloaded it, so that she can look in it. Now, if you really thought that she was asking to see your code, then why didn't you post your code in your following post? So please, don't try to rig your argument with twisted words.
    Now the thing that is puzzling me the most is the fact that you would expect someone to ask for your code when you have very clearly posted it in the original post, and you even claim that it's your code!
    Then a few posts later, you claim that the solution that I have given you is completely irrelevant to the problem you're experiencing, then for some bizarre reason you practically pretend that somehow that you didn't actually post your real code in the first post, but you then give me your 'real' code, and this 'real' code turns out to be the same code except that it uses the solution I suggested. So sometimes I wonder if you actually did post your real code at first but you don't want to admit you then used my solution. The whole thing just doesn't add up.
    The exact same statements can be dearly applied to the way you have acted in this thread. Furthermore, if you feel upset or 'put down' by the logical statements that I have presented to you in my previous post, you are one of a kind, and I am certainly not apologetic towards the way you feel. And no, I don't expect everyone to think along the same lines as me - but I do expect everyone who is smart enough to be dealing with code to have some signs of common sense.
    You must be joking if you think I'm even going to attempt to help you again reviewing the way you've acted towards any attempt at me giving you a solution or trying to pry information out of you about the bug. You can fool me once, but not twice. Finally again: if you feel insulted by the logical statements that I have presented to you in my last post, then you are one of a kind and I am not apologetic, because I feel that what I have said to you is very fair.
     
    Chronomus, Jun 17, 2010 IP