Zend Form Multiple Records - zend-framework

I'm getting to grips with Zend_Form and can create a form to add/edit a single database record, but now I'm trying to create a form to edit multiple records on a single page. For example, if I had a table of sports teams, and another table of players assigned to them teams I would want to be able to click on a team on my site and have all the players listed as rows with inputs to edit their names, date of births etc., with one submit button at the bottom to save any changes.
One thing to note is that there are a variable number of records that could be edited on a page; it is not a set amount.
Any pointers/help would be very much appreciated.
Thanks.

I use the code below to delete multiple items from the database.
On the index page (list of my database records):
<form method="post" action="<?php echo $this->baseUrl().'/admin/pages/deleteMultiple'; ?>">
<td class="checkboxTable"><input name="remove[<?php echo $data[$row]->id; ?>]" type="checkbox" id="checkbox[]" value="<?php echo $data[$row]->id; ?>"/></td>
<input class="deleteMultipleButtonBottom" name="deleteMultiple" type="submit" id="deleteMultiple" value="<?php echo $this->translate('Delete selected'); ?>">
</form>
The user sees a confirmation page:
<form method="post">
<input type="hidden" name="removeId" value="<?php echo implode($_POST['remove'], ','); ?>" />
<input class="deleteYes" type="submit" name="deleteMultiple" value="Yes" />
<input class="deleteNo" type="submit" name="deleteMultiple" value="No" />
</form>
And my action looks like this:
if($this->getRequest()->isPost())
{
if($this->getRequest()->isPost('remove'))
{
$this->view->pages = $this->pagesService->GetPages($this->getRequest()->getPost('remove'));
if($this->getRequest()->getPost('deleteMultiple') == 'Yes')
{
$this->pagesService->DeleteMultiplePages($this->getRequest()->getPost('removeId'), $this->view->user->username, $this->getRequest()->getPost('countedItems'));
}
elseif($this->getRequest()->getPost('deleteMultiple') == 'No')
{
$this->_helper->flashMessenger(array('message' => $this->view->translate('The pages were <u>not</u> deleted'), 'status' => 'notice'));
$this->_helper->redirectToIndex();
}
}
}
And in my service page:
public function DeleteMultiplePages($id)
{
$this->pages->delete('id IN (' . $id . ')');
}
This approach should work for updating values.

Related

Register membership after custom payment gateway

Hi I am trying to somehow create a custom payment gateway. The one I am using is integrated in Gravity Forms and I have created a new php gateway MeprTransactiumGateway.php to include this new custom gateway.
I am able to capture the payment but not assign the subscription to the member. The member is being registered in memberpress but with no Memberships.
This is the code I am editing:
public function display_payment_form($amount, $user, $product_id, $txn_id) {
$mepr_options = MeprOptions::fetch();
$prd = new MeprProduct($product_id);
$coupon = false;
$txn = new MeprTransaction($txn_id);
//Artifically set the price of the $prd in case a coupon was used
if($prd->price != $amount) {
$coupon = true;
$prd->price = $amount;
}
ob_start();
$invoice = MeprTransactionsHelper::get_invoice($txn);
//echo $invoice;
$email = MeprTransactionsHelper::get_email($txn);
echo do_shortcode("[gravityform id=\"4\" field_values=\"email=".$email."\" title=\"Subscription\" description=\"false\" ajax=\"true\"]");
/* ?>
<div class="mp_wrapper mp_payment_form_wrapper">
<form action="" method="post" id="payment-form" class="mepr-form" novalidate>
<input type="hidden" name="mepr_process_payment_form" value="Y" />
<input type="hidden" name="mepr_transaction_id" value="<?php echo $txn_id; ?>" />
<div class="mepr_spacer"> </div>
<input type="submit" class="mepr-submit" value="<?php _e('Submit', 'memberpress'); ?>" />
<img src="<?php echo admin_url('images/loading.gif'); ?>" alt="<?php _e('Loading...', 'memberpress'); ?>" style="display: none;" class="mepr-loading-gif" />
<?php MeprView::render('/shared/has_errors', get_defined_vars()); ?>
<noscript><p class="mepr_nojs"><?php _e('Javascript is disabled in your browser. You will not be able to complete your purchase until you either enable JavaScript in your browser, or switch to a browser that supports it.', 'memberpress'); ?></p></noscript>
</form>
</div>
<?php*/
}
The gravity form is being echoed using do_shortcode. The payment is going through. Then a success or fail message is displayed as confirmation. I would like that if a success message is received the membership is actually submitted (this was previously done in the html form code that is commented out)

Keep checkbox checked AND only check 1 checkbox per group

I'm looking to combine two things:
a) ensure that when a checkbox is checked, it remains checked after submit, AND
b) only allow one checkbox per group (e.g. the one below) be allowed to be checked at once. I can't use radio buttons unfortunately!
I can do a) & b) in isolation but unfortunately can't seem to combine them! Please help?
<form>
<input type="checkbox" name="a" value="low" <?php if(isset($_POST['a'])) echo "checked='checked'"; ?>/>
<input type="checkbox" name="b" value="mid" <?php if(isset($_POST['b'])) echo "checked='checked'"; ?>/>
<input type="checkbox" name="c" value="hi" <?php if(isset($_POST['c'])) echo "checked='checked'"; ?>/>
</form>
Using jQuery, I was able to create a function that will allow only one checkbox to be clicked at a time.
$('.check').click(function(){
if($('.check:checked').length == 1){
$('.check:not(:checked)').attr('disabled',true);
}
else if($('.check:checked').length == 0){
$('.check:not(:checked)').removeAttr('disabled');
}
});
<p>Check a box</p>
<input type="checkbox" class="check" />
<input type="checkbox" class="check" />
<input type="checkbox" class="check" />
DEMO

inserting text box input into URL parameter without GET method

In this form I want to get the value of the text box Enter Techs name: in to the URL but my form method is post.So that my url would look like
http://localhost/cs_3/index.php?page=chat&tech=
Is there any way I could do it.Can't use get method because I don't want the message to be seen in the URL.
<form method="post" >
<label>Enter Username:<input type="text" name="sender"/></label>
<?php if($user['Level'] == 3){?>
<label>Enter Clients name:<input type="text" name="tech"/></label>
<?php }else{ ?>
<label>Enter Techs name:<input type="text" name="tech" /></label>
<?php } ?>
<label>Enter Message:<textarea name="message" rows="8" cols="70"></textarea></label>
<div id="submit"><input type="submit" name="send" value="Send Message"></div>
</form>
You may use action param at your form.
Change it on key press in tech input by javascript (easy with jquery).

Form validation with onblur

Here is my form.
<form method="post" name="frm">
<label>Name*<input type="text" name="Name" value="<?php echo $r['Name'] ?>" onblur="if(this.value.length<3) alert('Name too short');" /></label>
<label>Username*<input type="text" name="UN" value="<?php echo $r['UN'] ?>" onblur="if(this.value.length<5) alert('Username too short');" /></label>
<label>Password*<input type="password" name="PW" onblur="validation()" /></label>
<label>Confirm Password*<input type="password" name="CM" onblur="validation()" /></label>
<?php } ?>
<input type="submit" name="Submit" value="<?php if($new) echo 'Register'; else echo 'Update'; ?>" />
</form>
Without writing separate onBlur events I am trying to get all these events into a function called validation() as I have done for password and confirm-password fields. Here is my validation function:
<script language="javascript">
function validation() {
var password = document.frm.PW.value;
var password2 = document.frm.CM.value;
if (password.length < 5) {
alert ("Password too short");
}
else if (password != password2) {
alert("password mismatch");
}
}
</script>
But with this code once I have filled password, and when I am about to start inputting for confirm-password field, it alerts the message "password mismatch". How to get rid of this? And for all the form tags if I am validating and using validation() function, then in each tag do I have to call onblur=validation()?
Don't have the password validation fired on the main password change - have it fired when you alter password2 or when you click submit. :)
If you insist on checking when you update password AND password 2, I would just add a check to see if password2 had been left blank:
else if(password !== password2 && password2 !== ""){
But doing ALL your checks on submit is a much cleaner solution (and as Rake says, it would be neater still to have a span that is updated instead of an alert).

Procees form no working well

I am trying to send this form, but this does not work
The processor in jquery :
function processorform(id)
{
jQuery(function()
{
var $ = jQuery;
$('.sp-poll-'+id+' form').submit(formProcess);
function formProcess(e) {
e.preventDefault();
var poll = $('input[name=poll]').val(),
answer = $('input[name=answer]:checked').val(),
div = $(this).parent(),
action = $(this).attr('action');
}
}
The HTML code
<div class="sp-poll-1">
<form method="post" action="include/submit.php" class="format" onsubmit="processorform('1');">
<input type="hidden" name="poll" value="<?php echo $pollid; ?>"/>
<input type="hidden" name="backurl" value="<?php echo $thisPage; ?>"/>
<input type="radio" name="answer" value="<?php echo $key; ?>" id="poll-<?php echo $pollid; ?>-<?php echo $key; ?>" class="sp-input-radio" />
<input type="submit" class="sp-btn" value="<?php _e('Send'); ?>"/></p>
</form>
</div>
When I try to send the form, it never works and always goes to submit.php and doesn't show the div results. I don´t know what´s wrong with the code or what the fix might be.
Thank´s for the help.
If you change this line:
onsubmit="processorform('1');"
to this:
onsubmit="processorform('1');return false;"
You won't go to submit.php.
But since you're using AJAX to post your request, some other errors may appear, since we don't have all the varibles to check if it will work.