Jump to content

Edit History

Adam40

Adam40

I would like to add my own form on the homepage in PrestaShop 1.7.

I add form fields in the tpl file displayed on the home page (e.g. in .tpl some module from home page). I would like to send it now with some simple php script, but it doesn't send anything to the email. How to do it?

Add php code to what class? Whether to add the php code to the new file with action = "link to the file form-send.php" Because after clicking send it does not send the form to the email. I don't want to use the built-in contact form because I have different fields with product configuration.


Below the code of the form and the php file.

 

tpl

						<form action="/form-send.php" method="post">
							<div class="col-xs-6">
								<div class="form-group">
									<label for="user" class="control-label">Name:</label>
									<input type="text" class="form-control" name="user" placeholder="Name and surname">
								</div>
								<div class="form-group">
									<label for="email" class="control-label">Email:</label>
									<input type="text" class="form-control" name="email" placeholder="e-mail address">
								</div>
								<div class="form-group">
									<label for="width" class="control-label">Width:</label>
									<input type="text" class="form-control" name="width" placeholder="cm">
								</div>
								<div class="form-group">
									<label for="length" class="control-label">Length:</label>
									<input type="text" class="form-control" name="length" placeholder="cm">
								</div>
								<div class="form-group">
									<label for="weight" class="control-label">Weight pack:</label>
									<input type="text" class="form-control" name="weight" placeholder="kg">
								</div>
								<div class="form-group">
									<button type="submit" class="btn btn-primary btn-lg">Send</button>
								</div>
							</div>
						</form>

 

php file

<?php
		$errorMessage = null;
		$successMessage = null;

		if ($_POST) {
			$user = isset($_POST['user']) ? filter_var($_POST['user'], FILTER_SANITIZE_STRING) : null;
			$email = isset($_POST['email']) ? filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) : null;
			$width = htmlspecialchars($_POST['width']);
            $length = htmlspecialchars($_POST['length']);
            $weight = htmlspecialchars($_POST['weight']);

			if (empty($user) || empty($email) || empty($width) || empty($length)|| empty($weight)) {
				$errorMessage = 'Complete all fields!';
			}

			if (is_null($errorMessage)) {
				mail(
					'[email protected]',
					'Form from my Shop',
					"Message: $width \n\n $length \n\n $weight \n\n Name: $user \n\n E-mail: $email",
					"From: $user <$email>"
				);

				$successMessage = 'Message was sent';
			}
		}
?>

 

Adam40

Adam40

I would like to add my own form on the homepage in PrestaShop 1.7.

I add form fields in the tpl file displayed on the home page (e.g. in .tpl some module from home page). I would like to send it now with some simple php script, but it doesn't send anything to the email. How to do it?

Add php code to what class? Whether to add the php code to the new file with action = "link to the file form-send.php" Because after clicking send it does not send the form to the email. I don't want to use the built-in contact form because I have different fields with product configuration.


Below the code of the form and the php file.

 

tpl

						<form action="/form-send.php" method="post">
							<div class="col-xs-6">
								<div class="form-group">
									<label for="user" class="control-label">Name:</label>
									<input type="text" class="form-control" name="user" placeholder="Name and surname">
								</div>
								<div class="form-group">
									<label for="email" class="control-label">Email:</label>
									<input type="text" class="form-control" name="email" placeholder="e-mail address">
								</div>
								<div class="form-group">
									<label for="width" class="control-label">Width:</label>
									<input type="text" class="form-control" name="width" placeholder="cm">
								</div>
								<div class="form-group">
									<label for="length" class="control-label">Length:</label>
									<input type="text" class="form-control" name="length" placeholder="cm">
								</div>
								<div class="form-group">
									<label for="weight" class="control-label">Weight pack:</label>
									<input type="text" class="form-control" name="weight" placeholder="kg">
								</div>
								<div class="form-group">
									<button type="submit" class="btn btn-primary btn-lg">wyślij</button>
								</div>
							</div>
						</form>

 

php file

<?php
		$errorMessage = null;
		$successMessage = null;

		if ($_POST) {
			$user = isset($_POST['user']) ? filter_var($_POST['user'], FILTER_SANITIZE_STRING) : null;
			$email = isset($_POST['email']) ? filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) : null;
			$width = htmlspecialchars($_POST['width']);
            $length = htmlspecialchars($_POST['length']);
            $weight = htmlspecialchars($_POST['weight']);

			if (empty($user) || empty($email) || empty($width) || empty($length)|| empty($weight)) {
				$errorMessage = 'Complete all fields!';
			}

			if (is_null($errorMessage)) {
				mail(
					'[email protected]',
					'Form from my Shop',
					"Message: $width \n\n $length \n\n $weight \n\n Name: $user \n\n E-mail: $email",
					"From: $user <$email>"
				);

				$successMessage = 'Message was sent';
			}
		}
?>

 

×
×
  • Create New...