掲示板

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

12年前 に Bea Bravo によって更新されました。

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

New Member 投稿: 5 参加年月日: 10/09/29 最新の投稿
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.
11年前 に Asier Hernández によって更新されました。

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

New Member 投稿: 24 参加年月日: 11/02/01 最新の投稿
Have you found any solution to this isuue??

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

Thanks in advance
thumbnail
11年前 に Miguel Ángel Júlvez によって更新されました。

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

Junior Member 投稿: 63 参加年月日: 11/03/29 最新の投稿
Any update about this issue?

Regards!
11年前 に Asier Hernández によって更新されました。

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

New Member 投稿: 24 参加年月日: 11/02/01 最新の投稿
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
11年前 に Miguel Ángel Júlvez によって更新されました。

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

Junior Member 投稿: 63 参加年月日: 11/03/29 最新の投稿
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!
11年前 に Asier Hernández によって更新されました。

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

New Member 投稿: 24 参加年月日: 11/02/01 最新の投稿
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
11年前 に Miguel Ángel Júlvez によって更新されました。

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

Junior Member 投稿: 63 参加年月日: 11/03/29 最新の投稿
It works!!!

Thanks Asier!
thumbnail
9年前 に Jose Jimenez によって更新されました。

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

Regular Member 投稿: 176 参加年月日: 12/08/23 最新の投稿
Hi guys,

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

Best regards,
Jose