Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need code to add simple registration form

Featured Replies

Hi,

I have a page which has three fields and one submit button on it

post-60027-0-56046100-1392058273_thumb.png

I need to add some code to send the details to an email address.

The current code is

		<form action="" method="post">
        <input type="hidden" name="recipient" value="email address goess here">
        <input type="hidden" name="subject" value="Subscription">
        <input type="hidden" name="redirect" value="">
        <input name="firstname" type="text" class="form" id="firstname" value="First Name">
        <input name="lastname" type="text" class="form" id="lastname" value="Last Name">
        <input name="email" type="text" class="form" id="email" value="Email">
   	    <input name="Submit" type="submit" class="submit" onClick="">
      	</form>

Thank you for your help.

 

EDIT: I would like to add that I would just like a popup to say thanks its been sent. The content of the whole site is on one page so I dont want it to go to another page to say submitted.

Edited by wivelden

Anyone help please?

I assume that you are using some sort of scripting language like PHP to process the form? You'll need this if you want to email the form fields to an email address and show a popup on successful submission of the form.

 

If you are indeed using PHP, you will need to check $_POST for the submitted form values (i.e., $_POST['first-name'], $_POST['last-name'] and $_POST['email'], if first-name, last-name and email are the names of the fields as set in the HTML of the form). You will then need to use for instance PHP's built-in mail() function to send these values to your email address. See http://uk1.php.net/manual/en/function.mail.php.

 

If the script finds the $_POST values, you will need to make sure the script adds the HTML code for the popup window to the outputted page.

 

If you're not using a scripting language like PHP and coded the site only in HTML you have a problem. You would then only be able to send the email by defining your form as follows:

<form action="MAILTO:someone@example.com" method="post" enctype="text/plain">

 

However, this means that the user will need to have an email client (like Outlook Express) installed on their device (which many users won't have) for this to work.

Thanks for the replies. I think I need to explain a little clearer. This was a template that had the fields already set in the template but no other files for the form. The html code that relates to these fields I have posted above. I have seen some free php forms but I don't know how to hook them up. I don't want a database. Just for the customer to fill in the three required fields and submit the info to an email address that then pops up a notification of sucess. Im not too good with this stuff hence why I am here for help. I hope that explains it better..

inlinedivblock this was actually an offer on our carnival day. :)

Edited by wivelden

Thanks for the replies. I think I need to explain a little clearer. This was a template that had the fields already set in the template but no other files for the form. The html code that relates to these fields I have posted above. I have seen some free php forms but I don't know how to hook them up. I don't want a database. Just for the customer to fill in the three required fields and submit the info to an email address that then pops up a notification of sucess. Im not too good with this stuff hence why I am here for help. I hope that explains it better..

 

There is a way.......

This is taken from PHP website http://uk1.php.net/manual/en/function.mail.php

 

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

Try the above code with your details at first! don't worry about the form and see if it sends anything!,

Then you can use your form to trigger the send . but we will get to that when you get this script to send something,

Ok I have sort of got it done myself. I had found a very basic script to do what I wanted but I do have a couple of little niggles that I hope one of you could help me with.

 

This is the current section for the form on my main and only page:

 

		<form action="contact.php" method="post">
            <input name="firstname" type="text" class="form" value="First Name">
            <input name="lastname" type="text" class="form" value="Last Name">
            <input name="email" type="text" class="form" value="Email">
   			<input name="submit" type="submit" class="submit" value="">
      	</form>

This is self explanatory as you can see above.

 

Clicking submit calls this php file and displays a pop up alert saying success or failure.

<?php
$field_name = $_POST['firstname'];
$field_last = $_POST['lastname'];
$field_email = $_POST['email'];

$mail_to = 'xxxxx@me.com';
$subject = 'Please add me to the Pats Coupon List!';

$body_message = 'First Name: '.$field_name."\n";
$body_message .= 'Last Name: '.$field_last."\n";
$body_message .= 'E-mail: '.$field_email;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
	<script language="javascript" type="text/javascript">
		alert('Thank you for registering. We have added your details to our memebers list and will send you some coupons very soon!.');
		window.location = 'index.html';
	</script>
<?php
}
else { ?>
	<script language="javascript" type="text/javascript">
		alert('Message failed. Please, send an email to email@gmail.co.uk');
		window.location = 'index.html';
	</script>
<?php
}
?>

 

Now onto my questions:

1) I want to be able to clear the fields on clicking them rather than having a clear button or clicking the 'x' which comes up when its clicked. The fields have text in them to show what goes where. Also to have the field names return if nothing is entered

 

2) The success/failure alert window comes up but the page behind it is cleared and just shows a blank/white page. How can I set it so that it just pops up over the current page? It does return as you can see in the code to the index.html but I don't want a redirect I just need it to pop up over the main page.

 

3) Currently you can submit the form without entering anything and it sends. How can I avoid this? I need a check for a valid email address. You can input anything into the boxes and it still sends.

 

I understand that this script is very basic and I am very new to building in html and css etc, so please if you can help just remember that I need you to hold my hand to guide me. :)

 

Thank you!

 

Site is viewable at http://www.patsfishandchips.co.uk/newsite

Edited by wivelden

Anyone help please?

Hi,

 

Sounds like you need some Jquery magic!!

Look up form validation and jquery focus inputs for removing the text when a user clicks on a input field. You can of course do this with Javascript, but if you don't know javascript Jquery will get you up and running quickly.

 

I would also recommend you sanitize your php POST fields, they will be vulnerable to attacks by spammers or people who would like to download or delete your database, have a little read of this http://www.php.net/manual/en/filter.filters.validate.php

 

The more controlled your fields are the better, try and not give the user too many free type fields, limit characters, use drop downs, radios etc....

Edited by inlinedivblock

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.