Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a form that visitors to my site can use to sign up for a class. The form is essentially:

<form method="post" action="registration.php">
<h1>Class Name</h1>
<input type="text" name="name">
<input type="email" name="email">
<button type="submit">
</form>

registration.php contains:

 $name = check_input($_POST['name'];
 $name = check_input($_POST['email'];

and some code to email that info. How can I have this also read the Class Name so that I can use that as the subject of the registration email?

Thanks.

share|improve this question
4  
Is the name of the class provided by PHP? If so, you can pass it as a hidden input. –  ಠ_ಠ Jun 17 '13 at 18:23
    
The name of the class is generated by JavaScript. This form is attached to a modal that pops up within a calendar. So the actual header is <h3 name="event" class="EventName"></h3> –  user2494467 Jun 17 '13 at 18:26
    
If you can get an id on that header, you can follow the example here: stackoverflow.com/questions/7764154/… –  ಠ_ಠ Jun 17 '13 at 18:29

2 Answers 2

There are a few ways you can achieve this.

1) Use a hidden form field (not my favored solution, but you don't have to add as much code)

2) Use an ajax call to submit the form rather than submitting via pure HTML.

For #1 you should add

<input type="hidden" name="class" value="My Class Value">

and then access it via $POST['class']

or

for #2 you could use something like jQuery.ajax()

share|improve this answer
1  
I lack the rep to vote you up, so I'll just thank you for the solution, the hidden input worked fine. –  user2494467 Jun 17 '13 at 18:40
    
Not a problem :) –  Braden Jun 18 '13 at 1:49

If the Class Content is given by php you could fill also a hidden input with that information:

<input type="hidden" name="class_name" value="<?php echo $className ?>">

You can also use Javascript.

<h1 class="classname">Class Name</h1>
<input type="hidden" name="class_name" id="classnameinput">
...
<script>
    textClassName = document.getElementById("classname").innerText;
    document.getElementById("classnameinput").value = textClassName;
</script>

Or jQuery...

<h1 class="classname">Class Name</h1>
<input type="hidden" name="class_name" id="classnameinput">
...
<script>
    jQuery(document).ready(function($) {
        textClassName = $('#classname').text()
        $('#classnameinput').val( textClassName );
    });
</script>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.