com.aoindustries.website.ContactForm Maven / Gradle / Ivy
/*
* aoweb-struts-core - Core API for legacy Struts-based site framework with AOServ Platform control panels.
* Copyright (C) 2009, 2016, 2018 AO Industries, Inc.
* [email protected]
* 7262 Bull Pen Cir
* Mobile, AL 36695
*
* This file is part of aoweb-struts-core.
*
* aoweb-struts-core is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* aoweb-struts-core is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with aoweb-struts-core. If not, see .
*/
package com.aoindustries.website;
import com.aoindustries.net.Email;
import com.aoindustries.validation.ValidationResult;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.GenericValidator;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.validator.ValidatorForm;
/**
* @author AO Industries, Inc.
*/
public class ContactForm extends ValidatorForm implements Serializable {
private static final long serialVersionUID = 1L;
private String from;
private String subject;
private String message;
@Override
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
setFrom("");
setSubject("");
setMessage("");
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = super.validate(mapping, request);
if(errors==null) errors = new ActionErrors();
if(!GenericValidator.isBlankOrNull(from)) {
ValidationResult fromCheck = Email.validate(from);
if(!fromCheck.isValid()) {
errors.add("from", new ActionMessage(fromCheck.toString(), false));
}
}
return errors;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy