View Full Version : Pass Variables from Form Submit ?
mrdjjohnson
07-27-08, 07:29 PM
Hello Everyone, I’m a little new to the Miva Scripting, and I’m trying to do a few test miva scripts. The first one that I’m trying to do is pass variables from a web submittal form (Basic Form Code Below), and Read the variables in the Miva Script application. If anyone has any examples or a better way to get user input’s please let me know.
<form method="POST" action="test.mv" >
<MvHIDE FIELDS="name,email,message"> ß Trying to make global Variable
<table width="350" border="0" align="center" cellpadding="0" cellspacing="5" >
<tr>
<td width="75" height="16"><strong>*Name:</strong></td>
<td width="285" align="left" valign="top"><input name="name" type="text" id="name" /></td>
</tr>
<tr>
<td width="75" height="20"><strong>*E-Mail:</strong></td>
<td align="left" valign="top"><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td width="75" height="97" valign="top"><strong>*phone:</strong> </td>
<td align="left" valign="top"><textarea name="phone" cols="30" rows="4" id="phone"></textarea></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
Bruce - PhosphorMedia
07-27-08, 09:23 PM
Dont need to use MvHide if your variables are in a form. variables within a form post or as part of a url are available to the recieving page.
mrdjjohnson
07-27-08, 09:56 PM
Bruce thank you for the comments, and took that out and I can use the variables still. Now that I’ve gotten the variables to pass from the form submittal page. I’m now processing the information in my Miva Script, and then trying to redirect to the previous page with another global variable or session string stating that the mail was sent. Below are a snip of the code that is the submittal, and the code that processes the e-mail. However, I was unable to find any documentation on a redirect function, therefore I embedded a JavaScript using that would redirect using window.location API. It is a little messy, but it works. If you guys have a cleaner way to go about it please let me know. Also, are there more detailed examples of creating a module online?
-- SNIP from Entry Page -----
<script language="JavaScript" type="text/JavaScript">
<!--
function FormValidator(theForm)
{
if (theForm.name.value == '')
{
alert("Please Enter Your Name.");
theForm.name.focus();
return (false);
}
if (theForm.email.value == '')
{
alert("Please Enter Your Email Address");
theForm.email.focus();
return (false);
}
if (theForm.phone.value == '')
{
alert("Please Enter Your Phone Number.");
theForm.phone.focus();
return (false);
}
if (theForm.message.value == '')
{
alert("Please Enter Your Message.");
theForm.message.focus();
return (false);
}
}
-->
</script>
<MvEval EXPR="{g.sendmail}">
<mvt:if expr = "g.sendmail">
<div align="center"><br><br>
<font color="red" size="+1"><b>Your Information has been sent. Thank you.</b></font>
</div>
<br>
</mvt:if>
<form method="POST" action="email.mv" onsubmit="javascript:return FormValidator(this);">
<table width="350" border="0" align="center" cellpadding="0" cellspacing="5" >
<tr>
<td width="75" height="16"><strong>*Name:</strong></td>
<td width="285" align="left" valign="top"><input name="name" type="text" id="name" /></td>
</tr>
<tr>
<td height="20"><strong>*E-Mail:</strong></td>
<td align="left" valign="top"><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td width="75" height="20"><strong>*Phone:</strong></td>
<td align="left" valign="top"><input name="phone" type="text" id="phone" /></td>
</tr>
<tr>
<td width="75" height="97" valign="top"><strong>*Message:</strong> </td>
<td align="left" valign="top"><textarea name="message" cols="30" rows="4" id="message"></textarea></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
------ SNIP from email.mv ------------
<MIVA STANDARDOUTPUTLEVEL = "text">
<MvSMTP
TO=Person@<DOMAINNAME>.com
FROM="NO-REPLY@<DOMAINNAME>.com"
MAILHOST="localhost"
CC=""
SUBJECT="SUBJECT">
Name: &[g.name]
E-mail: &[g.email]
Phone: &[g.phone]
Comments: &[g.message]
</MvSMTP>
<MvIF EXPR=MvSMTP_ERROR EQ "">
I would like to add a global variable here called sendmail so i can trigger the e-mail has been sent.... on the main entry page.
<BR>SENDING!<BR>
</MvIF>
Bruce - PhosphorMedia
07-27-08, 10:55 PM
usually, you just "redirect" content...not pages. For example, the "sign up" screen and "thanks" screen are in the same script...but the sign up form and thanks message wrapped in conditionals.
If you do want to "redirect" i suppose you could try using a meta redirect in the header wrapped in conditionals.
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.