Foros de discusión

Form enctype="multipart/form-data" + captcha

Bea Bravo, modificado hace 12 años.

Form enctype="multipart/form-data" + captcha

New Member Mensajes: 5 Fecha de incorporación: 29/09/10 Mensajes recientes
Hello,

I'm use Liferay 6.0 and I'm programming a portlet who contains one form. This form has the enctype "multipart/form-data"" because has a field for upload a file. This form use the captcha of Liferay also. The form works succesfully when it has not captcha.

<form:form name="formStep1" commandName="solicitud" method="post" action="${formStep2ActionUrl}" enctype="multipart/form-data">
<form:input type="text" path="nombre" name="nombre" id="nombre"/>
....
<form:input id="file" name="file" type="file" path="file" />
...
</form:form>


But when I add the code corresponding of catcha, the portlet fails (Text verification failed.):

<form:form name="formStep1" commandName="solicitud" method="post" action="${formStep2ActionUrl}" enctype="multipart/form-data">
<form:input type="text" path="nombre" name="nombre" id="nombre"/>
....
<form:input id="file" name="file" type="file" path="file" />
....
<liferay-ui:captcha url="<%= captchaURL %>" />
...
</form:form>


If I put enctype="multipart/form-data" the upload file works fine but the catpcha no. If I don't put enctype="multipart/form-data", the captcha works fine but the upload file no. Anybody can help me, please? How can I resolve this?

Thank you.
Bea.
Asier Hernández, modificado hace 11 años.

RE: Form enctype="multipart/form-data" + captcha

New Member Mensajes: 24 Fecha de incorporación: 1/02/11 Mensajes recientes
Have you found any solution to this isuue??

I have the same problem with captcha and multipart/form data.

Thanks in advance
thumbnail
Miguel Ángel Júlvez, modificado hace 11 años.

RE: Form enctype="multipart/form-data" + captcha

Junior Member Mensajes: 63 Fecha de incorporación: 29/03/11 Mensajes recientes
Any update about this issue?

Regards!
Asier Hernández, modificado hace 11 años.

RE: Form enctype="multipart/form-data" + captcha

New Member Mensajes: 24 Fecha de incorporación: 1/02/11 Mensajes recientes
Yes, here is how I have resolved this issue:


	<c:if test="<%= requireCaptcha %>">		
			<portlet:resourceurl var="captchaURL">
				<portlet:param name="<%= Constants.CMD %>" value="captcha" />
			</portlet:resourceurl>	
			<liferay-ui:captcha url="<%= captchaURL %>" />		
	</c:if>


I hope this will help you.
thumbnail
Miguel Ángel Júlvez, modificado hace 11 años.

RE: Form enctype="multipart/form-data" + captcha

Junior Member Mensajes: 63 Fecha de incorporación: 29/03/11 Mensajes recientes
Thanks Asier but I've that piece of code and it doesn't work

This is the error line in catalina.out
ERROR [SimpleCaptchaImpl:398] Captcha text is null. User null may be trying to circumvent the captcha.

It happens when I send a multipart form with captcha

Regards!
Asier Hernández, modificado hace 11 años.

RE: Form enctype="multipart/form-data" + captcha

New Member Mensajes: 24 Fecha de incorporación: 1/02/11 Mensajes recientes
I think youl will have to change the code in your Portlet class. In my code I have my WebFormPortlet.java with this code in the saveData method:



		if (requireCaptcha) {
			try {
				//CaptchaUtil.check(actionRequest);
				String enteredCaptchaText = ParamUtil.getString(uploadRequest, "captchaText");				

		        PortletSession session = actionRequest.getPortletSession();
		        //String captchaText = getCaptchaValueFromSession(session);
		        String captchaText = "";
		        Enumeration<string> atNames = session.getAttributeNames();
		        while (atNames.hasMoreElements()) {
		            String name = atNames.nextElement();
		            if (name.contains("CAPTCHA_TEXT")) {
		            	captchaText = (String) session.getAttribute(name);
		            }
		        }		        
		        if (Validator.isNull(captchaText)) {
		            throw new Exception("Internal Error! Captcha text not found in session");
		        }
		        if (!StringUtils.equals(captchaText, enteredCaptchaText)) {
		            throw new Exception("Invalid captcha text. Please reenter.");
		        }
			}
			catch (CaptchaTextException cte) {
				SessionErrors.add(
						actionRequest, CaptchaTextException.class.getName());

				return;
			}
		}

</string>


And this would be my serveResource method:



	public void serveResource(
			ResourceRequest resourceRequest, ResourceResponse resourceResponse)
		throws IOException, PortletException {

		String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);
		
		try {
			if (cmd.equals("captcha")) {
				//serveCaptcha(resourceRequest, resourceResponse);
				com.liferay.portal.kernel.captcha.CaptchaUtil.serveImage(resourceRequest, resourceResponse);
			}
			else if (cmd.equals("export")) {
				exportData(resourceRequest, resourceResponse);
			}
		}
		catch (Exception e) {
			_log.error(e, e);
		}
	}



Try if this is a valid solution for your problem.
thumbnail
Miguel Ángel Júlvez, modificado hace 11 años.

RE: Form enctype="multipart/form-data" + captcha

Junior Member Mensajes: 63 Fecha de incorporación: 29/03/11 Mensajes recientes
It works!!!

Thanks Asier!
thumbnail
Jose Jimenez, modificado hace 9 años.

RE: Form enctype="multipart/form-data" + captcha

Regular Member Mensajes: 176 Fecha de incorporación: 23/08/12 Mensajes recientes
Hi guys,

this should be fixed in https://issues.liferay.com/browse/LPS-51956

Best regards,
Jose