Jump to content

help with form processing


jan23778

Recommended Posts

Hi everyone.

 

I am very new to PHP and have been trying to write a form processing script form about a month now with no joy. I am slowly becoming insane and have teared half of my hair out already!! Any help anyone can give me would be much appreciated.

 

Whenever I upload this script to my website (well one that I am trying to do for a friend), fill in the fields and press submit a blank page comes up. I really do not know what more to do and am becoming desperate.

 

Just to be an even bigger pain in the backside I have to tell you that my friend is Spanish and so is the website!

 

The PHP is the following:

 

<?php



    $send = true;
    $email = $_POST['email'];
    $contactname = $_POST['contactname'];
    $telephone = $_POST['telephone'];
    $email = $_POST['email'];
    $detalles = $_POST['detalles'];
    $tipo = $_POST['tipo'];

    $recipient = "jan_colombini@hotmail.com"; 

$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) or die("<h4>Correo Invalido</h4> <a href='javascript:history.back(1);'>Atras</a>"); 

  echo "<a href='javascript:history.back(1);'>Atras</a>";

} elseif ($detalles == "") {

  echo "<h4>Sin Mensaje</h4>";

  echo "<a href='javascript:history.back(1);'>Atras</a>";

}



/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */

    if($send != false) {
    mail($recipient, $email, $contactname, $telephone, $email, $detalles, $tipo);
      echo "<h4>Su mensaje ha sido enviado</h4>";
    } else {
      echo "<h4>No se ha realizado el envio de informaciones a $email</h4>";
    } 

/** error handler
    ** set error reporting level to 0 for live site, 1 for dev */
ini_set("display_errors", 1); 
ERROR_REPORTING(E_ALL); 


?>

 

And my HTML is :

 

      <form action="form.php" method="post" class="contact">

        <fieldset>

         

          <div>

            <label for="contactname" class="fixedwidth">Nombre y Apellido</label>

            <input type="text" name="contactname" id="contactname"/>

          </div>

          <div>

            <label for="telephone" class="fixedwidth">Numero de Telefono</label>

            <input type="text" name="telephone" id="telephone"/>

          </div>

          <div>

            <label for="email" class="fixedwidth">Correo Electronico</label>

            <input type="text" name="email" id="email"/>

          </div>

          <div>  

              <label for="tipo" class="fixedwidth">Tipo de Seguro</label>

              <select name="tipo" id="tipo">     

                <option>Rodaje de spots</option>

                <option>Sesiones de Fotografía</option>

                <option>Cortometrajes</option>     

                <option>Otros suguros</option>  

              </select> 

            </div>

            <div>

              <p>Texto</p>

              <div class="textarea">

              <textarea name="detalles" id="details" cols="30" rows="7"></textarea>

              </div>

<div class="buttonarea">



  <input type="submit" value="Envianos la informacion"/>



</div>

            </div>

           <p>Una vez recibida su consulta nos pondremos en contacto con usted en la mayor brevedad</p>

        </fieldset>

      </form>

 

I have been told that it may be best to combine my variables before I call the function but I am really new at this and have no idea how to do that.

 

Please could someone give me a hand with this.

Link to comment
Share on other sites

Hi and thanks for the replies,

 

I have now put the error handling at the top but nothing has changed. I am sorry but I am very very new to this. How does the error handler work? Should it show the errors when I press submit? I put it at the top, filled in the form and pressed submit but it still just shows a blank page.

 

Do you have any more advice? I really want to get this to work and would be a huge step for me.

 

By the way I did not change the opening if statement (I did not miss it when pasting it just is not there) as I am not 100% sure of what it should contain. I have changed this script so much that I am completely lost!!!!

 

<?php


/** error handler
    ** set error reporting level to 0 for live site, 1 for dev */
ini_set("display_errors", 1); 
ERROR_REPORTING(E_ALL); 



    $send = true;
    $email = $_POST['email'];
    $contactname = $_POST['contactname'];
    $telephone = $_POST['telephone'];
    $email = $_POST['email'];
    $detalles = $_POST['detalles'];
    $tipo = $_POST['tipo'];

    $recipient = "jan_colombini@hotmail.com"; 

$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) or die("<h4>Correo Invalido</h4> <a href='javascript:history.back(1);'>Atras</a>"); 

  echo "<a href='javascript:history.back(1);'>Atras</a>";

} elseif ($detalles == "") {

  echo "<h4>Sin Mensaje</h4>";

  echo "<a href='javascript:history.back(1);'>Atras</a>";

}



/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */

    if($send != false) {
    mail($recipient, $email, $contactname, $telephone, $email, $detalles, $tipo);
      echo "<h4>Su mensaje ha sido enviado</h4>";
    } else {
      echo "<h4>No se ha realizado el envio de informaciones a $email</h4>";
    } 



?>

 

Thank you all for your help (and patience) I do appreciate it!!

Link to comment
Share on other sites

Ah OK,

 

What I wanted is to send the message "Sin Mensaje" if the "detalles" field was left blank otherwise go to the next section (Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise.)

 

Would I be missing anything if I just changed that to:

 

}if ($detalles == "")

 

Also to send the details ($email, $contactname, $telephone, $email, $detalles, $tipo) to the recipient (jan_colombini@hotmail.com) have I got this section right? 

 

mail($recipient, $email, $contactname, $telephone, $email, $detalles, $tipo);

 

It doesn't make sense to me as it seems to suggest that it will mail the recipient field (my email address) along with all the other details but I do not know how to tell it to mail the detail TO me.

 

As I said I am still very new and it seems like I am trying to learn another language!!! (and with a different alphabet)

 

Thank you again for all your help, if you have any other suggestions they would be gratefully received!!

 

 

Link to comment
Share on other sites

shud be

}if ($detalles == "") {

 

{ and } denotes a block of code. so these must come in pairs (cant have } without a {)

 

the mail function

bool mail  ( string $to  , string $subject  , string $message  [, string $additional_headers  [, string $additional_parameters  ]] )[/code]

 

it returns TRUE (Success) or FALSE (Failed)

 

$to is who yer sending the email to

$subject is the subject line for the email

$message is the body of yer email

 

the rest u can ignore, unless u need to add BCC or other special fields.

Link to comment
Share on other sites

Tbh, I'd recommend reading a book or an online tutorial as you seem unfamiliar with the syntax of PHP and its functions.

 

It appears that you've copied the script from http://www.buildwebsite4u.com/advanced/php.shtml or something of the sort. I'd strongly recommend against this, in favour of actually sitting down and learning how the script works, if you're actually serious about learning PHP.

 

http://www.tizag.com is where I first started - it's pretty simple.

Link to comment
Share on other sites

You are right, I am unfamiliar with PHP. I have a book on Javascript that I am trying to follow and have been following some tutorials on PHP as well (and trying to amend the script to fit my needs). I have done a basic website for a friend of mine. I was without a job for a period of time and therefore wouldn't have minded spending a lot of time learning PHP, but have recently got back into employment and have found myself really short on time. I have left his website unfinished and I guess I was looking for a shortcut to be able to finish his site off.

 

I will go on to www.tizag.com to try and start form scratch again instead of trying to combine 5 different tutorials into one.

 

Thanks for the advice

Link to comment
Share on other sites

Lol yeah. It really is worth learning what's going on rather than simply copying though - that way you can successfully modify scripts ;)

 

Anyway yeah, good luck. PHP is pretty easy tbh; you'll be able to write your own mail script pretty soon.

 

If you get stuck on anything in particular, feel free to pm me.

Link to comment
Share on other sites

ahhhh, but dun give up.

I knew C before i got started, that helped a lot in learning php. But I got very interested in an open source project. and started making mods for it. It took like 3 months from writing small mods to big huge ones.

and a few bookmarks and tools to help.

an editor which has code folding, syntax highlighting, and tooltips. Currently using PHPDev (Sourceforge) for an editor as it does these basic things, also hitting f1 takes you to the help page of the function at php.net.

a list of good sites, most often as I said php.net answers my questions, or I look at questions here, great place to learn.

and dont forget to keep yer code beautiful, indent ... indent ... indent

Keeping it beatiful can save u countless hours of debugging a script (especially for unbalanced {} () '' "").
[url=http://thephppro.com/tools/beautify.php]PHP Beautifier for ugly code

 

:)

 

Good luck

 

Link to comment
Share on other sites

Hi all,

 

Thank you for your advice, I do want to learn PHP so please do not think I just pasted some code I found and wanted you all to do my work for me. I will carry on and become good, I am not one to quit anything!!

 

I am really enjoying trying to learn something new and its nice to know there is so much help available when it is needed. Keep up the good work and I am sure you will hear from me again the next time something trips me up.

Link to comment
Share on other sites

Good stuff. Yeah, PHP is a lot of fun :D

 

I know a bit of C++, but like...what can you really do with it? Unless you're like a guru and you can code GUIs and stuff, it's pretty boring. PHP on the other hand is really easy to pick up, and fun to mess around with.

 

So yeah, good luck.

Link to comment
Share on other sites

Just dun worry about learning it all.

as with C/C++ u dun need to learn the functions libraries.

learn the basics of the language.

 

after u get the basics of the language, than delve into using the functions that u need.

 

Yes, there are gonna be times, when u will replicate a function that already exists.

and ya can tell yerself, that u know how it can be done, u know how it works.

 

there are too many ppl that rely on prebuilt code, yet have no clue how that code works.

 

Link to comment
Share on other sites

Yeah, I'm trying :P I've got the hang of command line stuff - it's basically the same as PHP. It's just GUI stuff I find really enigmatic.

 

Yeah, I agree with the point about people relying on prebuilt code. I don't really believe in it at all myself - I have written 99% of what's on my site, and the 1% is stuff I've had help with, but I know how it works.

 

Much more satisfying knowing your code like the back of your hand :)

Link to comment
Share on other sites

PHP is server side and javascript is client side. PHP is for processing and databases and stuff, and javascript is for dynamically doing stuff on the client's pc. I'd make it a mission to learn both, as they work really well together :)

 

I used both languages tremendously in my site, and it's paid off...

 

Plus, you can combine them into AJAX where you can dynamically update pages; jolly good stuff.

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.