Reputation: 1211
I have made a simple HTML form in Liferay. When the form is submitted, its content should go to my email address and a line saying 'thank you' is to be displayed. I have done the action part with php. But after submitting, all I get is the 'thank you' part and the form doesn't get submitted to my email address.
Any idea why this doesn't work? I am not good with PHP at all. Only the basics.
Is there any other way to do this? e.g with javascript? though that might not be a good option.
I am using Liferay 6.1 and Tomcat 7.
HTML form:
<form name="form" method="post" action="form.php">
<table>
</tr>
<tr>
<td>
<label for="first_name">First Name</label>
</td>
<td>
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="last_name">Last Name</label>
</td>
<td>
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
</table>
</form>
PHP:
<?php
if(isset($_POST['email'])) {
// Email where form is sent:
$email_to = "[email protected]";
Thank you!
<?php
}
die();
?>
Upvotes: 0
Views: 1275
Reputation: 4508
I had a problem with php portlets in version 6.2 for $_POST params. The solution was to put the portlet prefix in the parameter this way
<input name="_SamplePHP_WAR_samplephpportlet_foo" type="text" />
that wil make $_POST['foo'] have a parameter
Upvotes: 0
Reputation: 1211
Finally got the answer with JSP, which I haven't used since school days. Here is the code in case someone wanted to try it.
<%@ page import="sun.net.smtp.SmtpClient, java.io.*, javax.servlet.http.HttpServletResponse, javax.servlet.jsp.PageContext,java.util.*" %>
<%
String from= request.getParameter("from");
String to= request.getParameter("to");
try{
SmtpClient client = new SmtpClient("smtp.mysitedomain.com");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("From: " + from);
message.println("To: " + to);
message.println();
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String paramValue = request.getParameter(paramName);
message.println(paramName + ":" + paramValue);
}
client.closeServer();
}
catch (IOException e){
System.out.println("ERROR IN DELIVERING THE FORM:"+e);
}
response.sendRedirect("thanks.htm");
%>
Upvotes: 1
Reputation: 556
Liferay is able to use PHP Portlets, but you will have to do some configurating, maybe this link can help your case: http://www.liferay.com/community/wiki/-/wiki/Main/PHP+Portlets
Upvotes: 0