Jump to content

Checkbox, foreach, articles, formmailer


rolspace.net
 Share

Recommended Posts

Hi

Started this thread before, still need help with something. I have several articles (Shirts) in a "shop". The visitor can check a checkbox to chose the article. The name of this chosen article should be written in the form under "article". How do I link the individual checkbox to this field?

That's what I have so far:

the checkbox (under "name" the article is identified from the database:

<label><input type="checkbox" id="checkbox" name="<?php echo $article->article_description ?>" <?php             
                echo ($article->article_reserved == 1) ? ' disabled' : ''; ?> class="checkbox style-2 pull-right  ">I want this!&nbsp;
</label>

Then, in the contact form, I have the following:

<div class="form-group">
            <label for="product">Article:</label>
            <input type="text" class="form-control" name="product" id="product"
                value="<?php
                            echo $article->article_description;                                                              
                       ?>" required>
</div>

I guess I need a foreach code and an if else code to make it work, but I can't figure out how to do it. HELP!

 

Link to comment
Share on other sites

I can see two options:

1. Use Javascript to write something that identifies the article into a field in your form when a checkbox is checked. I can see this getting fiddly when it comes to dealing with multiple selected articles and removing articles from the field if their checkbox is later unchecked.

2. Place the articles inside the form, so checked articles are included with the form submission. Then when you process the form you look for checked articles.

 

14 hours ago, rolisx said:

<input type="checkbox" id="checkbox" name="<?php echo $article->article_description ?>"

PS. I recommend you use something without spaces for your input name, e.g. $article->name

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...