Forums de discussion

Web form portlet customization

Henrik Bernström, modifié il y a 14 années.

Web form portlet customization

Junior Member Publications: 43 Date d'inscription: 05/10/07 Publications récentes
Hi,

I've got an interesting and challenging task ahead of me in customizing the web form portlet. What I need to have is a form that a user fills in and when submitting, the form needs to, in some way, retreive user session data from another web system / application and add that to the email to be sent. Therefore I can't rely on some server-side call (curl / wget) to fetch the session data, of course. It needs to be initiated from the client itself, using an iFrame or whatever. I can not use ajax as the other system is not within the same domain.

Do you have any ideas of how to go about with this task? Ignore the other system, it's within Liferay the actual challenge is for me.

Thanks in advance!

/Henrik
Henrik Bernström, modifié il y a 14 années.

RE: Web form portlet customization

Junior Member Publications: 43 Date d'inscription: 05/10/07 Publications récentes
I wonder what I was thinking... how could this ever be solved with an iFrame?

Anyway, I solved it by setting, reading and submitting a cookie value using javascript. This was possible as the both web applications share the same parent domain.

This was the two javascript functions required:

<script type="text/javascript">

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setSaeInfoAndSubmit(aForm) {
	aForm.elements[aForm.elements.length-2].value += getCookie('SAE_INFO');
	aForm.submit();
}

</script>


And it's triggered by the onclick event of the form button (previously a submit button).

<input type="button" value="<liferay-ui:message key=" send">" onclick="javascript:setSaeInfoAndSubmit(this.form);" /&gt;


Now, good or not, it works. Is there a smarter, more maintainable way of doing it? How would you have solved it?
thumbnail
Erik Andersson, modifié il y a 14 années.

RE: Web form portlet customization

Junior Member Publications: 39 Date d'inscription: 08/04/08 Publications récentes
Hi Henrik,

See you have solved your problem already. My way to go about it would've been using a web proxy. Did you consider this? If so, what made you not use such a solution?

Also, I know there are flash bridges out there (flash allows cross browser requests). Have not used a flash bridge on any project yet though.

Cheers,
Erik