我尝试使用google sites的HtmlService将表单对象从html文件传递到库文件 - 这是未定义的。 我的html文件也在同一个库中:
<script>
function AlertUser(message)
{
alert ( message );
}
</script>
<? var betType = GetBetsType(); ?>
<? if( VerifyTimesUp( betType ) == false ) { ?>
<? var curRound = getCurrentRoundObj(); ?>
<h> <?= curRound.roundName ?> round <?= curRound.roundNumber ?> Bets: <br><br></h>
<? var betsData = GetBetsData( betType ); ?>
<? var firstGameNumber = 1 + (curRound.roundNumber - 1)*curRound.fixtureNumber; ?>
<? var lastGameNumber = firstGameNumber + curRound.fixtureNumber; ?>
<form id="myForm1">
<? for (var i = firstGameNumber; i < lastGameNumber; i++) { ?>
<p style="text-align:left;"> Game <?=(i-firstGameNumber+1) ?>: <?= betsData[i][2] ?> vs <?= betsData[i][3] ?>
<input name="homeResult<?i?>" type="text" style="float:right" />
<input name="awayResult<?i?>" type="text" style="float:right" /> <br><br>
</p>
<? } ?>
<br>
<input type="button" value="Submit"
onclick="google.script.run
.withSuccessHandler(AlertUser)
.ProcessForm(this.form);"/>
</form>
<? } ?>
Process Form函数在我的非库函数中定义:
function doGet()
{
siteFunctions.UpdateBetsType('GroupStage');
return siteFunctions.CreateHTMLBetsTemplate()
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
}
function ProcessForm(formObject)
{
return siteFunctions.GeneralProcessForm(formObject);
}
我的库代码如下:
function CreateHTMLBetsTemplate()
{
return HtmlService.createTemplateFromFile('BetsTemplateHTML');
}
function UpdateBetsType( newBetsType )
{
curBetType = newBetsType;
}
function GetBetsType()
{
return curBetType;
}
function GeneralProcessForm(formObject)
{
var roundObj = getCurrentRoundObj();
var firstGameNumber = 1 + (roundObj.roundNumber - 1)*roundObj.fixtureNumber;
var lastGameNumber = firstGameNumber + roundObj.fixtureNumber;
for( var i=firstGameNumber; i<=lastGameNumber; i++ )
{
eval( 'var curInput = formObject.homeResult' +i);
if( (curInput == '') || (curInput.toString() != curInput) )
return ('Invalid Bet: Home result in game ' + (i-firstGameNumber+1) + 'is not a valid number');
}
}
在GeneralProcessForm函数中,我得到formObject未定义。
有人有想法吗?