Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-18-2007, 04:34 PM
Junior Member
 
Join Date: Nov 2007
Posts: 1
Default submit a form with ajax without redirection

hi,
i am new here and this is my first post, i wanna know how to run ajax code when the form submit without making form redirection. here is the code:

<HTML>
<HEAD>
<TITLE>Send Gifts</TITLE>
<script type="text/javascript" src="public/scripts/prototype.js"></script>
<script type="text/javascript" src="public/scripts/sending.js"></script>
</HEAD>



<BODY>

<label><h1>Gifts world!</h1></br></label>

<a href=<?php echo $this->baseUrl."/index/index";?>>Send a Gift</a>
<a href=<?php echo $this->baseUrl."/index/receivedShow";?>>Received</a>
<a href=<?php echo $this->baseUrl."/index/inviteShow";?>>Invite</a>
</br>
<form>
<?php if ($this->giftsLinks)
{

$giftsEnableStatus = "";
if(!$this->friendsNamesList)// check if the user does not have friends, then turn the RadioButtons off
{
$giftsEnableStatus = "DISABLED";
}

// building the gifts table
echo "<table border=\"4\"><tr>";

$colCounter = 0; // To count the no of columns in each row

for ($i = 0; $i < count($this->giftsLinks); $i++)
{
$checkFirst = ""; // this variable is used to check the first gift in the page
if($i % 24 == 0)
$checkFirst = "CHECKED";

if ($colCounter == 6) {
$colCounter =0;
echo "</tr>";
// if there are still some elements make a new row
if ($i != count($this->giftsLinks))
echo "<tr>";
}
echo "<td>
<IMG SRC = \"".$this->escape($this->giftsLinks[$i])."\" WIDTH = \"70\" HEIGHT = \"70\"></br>
<inPUT TYPE=\"radio\" NAME=\"giftsRadio\" VALUE=\"".$this->escape($this->giftsIDs[$i])."\"".$giftsEnableStatus." ".$checkFirst.">Send this
</td>";
$colCounter++;
}

echo "</table>";
}
?>

</br>
<label for=\"FriendsList\">Frindes list:</label>
<select name=\"FriendsList\">
<?php
foreach ( $this->friendsNamesList as $friendName )
{
echo "<option value=\"".$this->escape($friendName['uid'])."\">".$this->escape($friendName['name'])."</option>";
}
?>
<?php if(!$this->friendsNamesList)
{
echo "<label><h1>You should at least have one friend to start sending Gifts</h1></br></label>";
}
else
{
?>
</select>
</br>

</br>
<label for="CommentArea">Add a comment:</label>
</br>
<textarea name="CommentArea" rows="3" cols="30"></textarea>
</br>

</br>
<label ><h4>Sending options: </label>
<inPUT TYPE="radio" NAME="sendOptions" VALUE="sendMail" CHECKED>Send Email
<inPUT TYPE="radio" NAME="sendOptions" VALUE="notSendMail">Don't send Email
</br>
<input type="button" value="Send your gift" onclick="send(sendOptions.value, giftsRadio.value, CommentArea.value)"/>
<?php }// end else ?>
<span id='sendingResult' style="color:#00DD45;"></span>
</form>
</BODY>

</HTML>


i tried to put the form action to an action where the code in there is:

$this->_helper->viewRenderer->setNoRender(); and using the onsubmit="my ajax action"

but it does not work, it is directing me to another page. all this problem appears coz i wanna extract the radio button value from the form, but it should make submit to have a value. can any body help me here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-21-2007, 11:03 AM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default

Not sure I fully understand what it is that you are trying to do.. but since you are using prototype.js a form submit could be as simple as this.

function submitForm()
{
$('myForm').request({
onSuccess: function(transport)
{
$('someContainer').update(transport.responseText);
}
})
}

'myForm' would in this case be the form you want to submit and 'someContainer' could be a div (or anyother element) that you want to contain the response from the controller handling the form post.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:34 PM.