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

I'm creating a custom mailchimp form template for my users.

So I would like to extract ONLY form action url from mailchimp code..

Can someone tell me how to extract action url from the following code.

<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="http://xxxxxxxx.us5.list-manage.com/subscribe/post?u=xxxxxxxxxxxxxxxxxx&amp;id=xxxxxxx" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <h2>Subscribe to our mailing list</h2>
<div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
<div class="mc-field-group">
    <label for="mce-EMAIL">Email Address  <span class="asterisk">*</span>
</label>
    <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div class="mc-field-group">
    <label for="mce-FNAME">First Name </label>
    <input type="text" value="" name="FNAME" class="" id="mce-FNAME">
</div>
<div class="mc-field-group">
    <label for="mce-LNAME">Last Name </label>
    <input type="text" value="" name="LNAME" class="" id="mce-LNAME">
</div>
    <div id="mce-responses" class="clear">
        <div class="response" id="mce-error-response" style="display:none"></div>
        <div class="response" id="mce-success-response" style="display:none"></div>
    </div>  <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
</form>
</div>

<!--End mc_embed_signup-->
share|improve this question
 
you want to extract using jQuery or PHP –  Mahesh.D Jun 13 at 11:23
 
@Mahesh.D I want to store it in a php variable. –  Giri Jun 13 at 11:24
 
using jQuery we can extract easily from there you can send to your controller –  Mahesh.D Jun 13 at 11:29
 
once have look at this –  Mahesh.D Jun 13 at 11:30
 
Something like this may work '/action="(.*?)\"/s' –  Dave Jun 13 at 11:30
add comment

2 Answers

up vote 2 down vote accepted
preg_match('|form action="([^"]*?)" method="post" id="mc-embedded-subscribe-form"|i', $html, $matches);
$url = $matches[1];
share|improve this answer
1  
Hello and welcome to StackOverflow ! Thanks for your input, next time try to put some text, preferably some explanation. –  HamZa Jun 13 at 11:44
add comment

Ok, I solved it by myself.

$x = '<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="http://xxxxxxxx.us5.list-manage.com/subscribe/post?u=xxxxxxxxxxxxxxxxxx&amp;id=xxxxxxx" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <h2>Subscribe to our mailing list</h2>
<div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
<div class="mc-field-group">
    <label for="mce-EMAIL">Email Address  <span class="asterisk">*</span>
</label>
    <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div class="mc-field-group">
    <label for="mce-FNAME">First Name </label>
    <input type="text" value="" name="FNAME" class="" id="mce-FNAME">
</div>
<div class="mc-field-group">
    <label for="mce-LNAME">Last Name </label>
    <input type="text" value="" name="LNAME" class="" id="mce-LNAME">
</div>
    <div id="mce-responses" class="clear">
        <div class="response" id="mce-error-response" style="display:none"></div>
        <div class="response" id="mce-success-response" style="display:none"></div>
    </div>  <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
</form>
</div>

<!--End mc_embed_signup-->';
preg_match_all('!http?://[\S]+!', $x, $matches);
$all_urls = $matches[0];
var_dump($all_urls);
share|improve this answer
add comment

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.