Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I apply styling #44

Open
nirajupadhyay11 opened this issue Mar 30, 2020 · 5 comments
Open

How do I apply styling #44

nirajupadhyay11 opened this issue Mar 30, 2020 · 5 comments

Comments

@nirajupadhyay11
Copy link

How do I apply material-ui styling to

<MailchimpSubscribe url={url}/>

I am only using email for subscription and my form is as follows

<form onSubmit={formData => subscribe(formData)}> <TextField variant="outlined" margin="normal" required type="email" fullWidth id="email" label="Email Address" name="EMAIL" autoComplete="email" autoFocus onChange={e => setEmail(e.target.value)} /> <Button type="submit" fullWidth variant="contained" color="primary" className={classes.submit} > Subscribe </Button> </form>

@revolunet
Copy link
Owner

what is your problem exactly ?

@nirajupadhyay11
Copy link
Author

I am creating the app using reactjs and material-ui. Since I am trying to use only email to subscribe to mailchimp, I wanted to use
<MailchimpSubscribe url={url}/>
to do so.

But, I also want the email field on my page to look like the attached screenshot
image

So, here is how I used your component to do so

`<MailchimpSubscribe
url={mailchimpurl}
render={({ subscribe, status, message }) => (

    <form onSubmit={formData => subscribe(formData)}>
      <TextField
        variant="outlined"
        margin="normal"
        required
        type="email"
        fullWidth
        id="email"
        label="Email Address"
        name="EMAIL"
        autoComplete="email"
        autoFocus
        onChange={e => setEmail(e.target.value)}
      />
      <Button
        type="submit"
        fullWidth
        variant="contained"
        color="primary"
        className={classes.submit}
      >
        Subscribe
      </Button>
    </form>
    {status === "sending" && <div style={{ color: "blue" }}>sending...</div>}
    {status === "error" && <div style={{ color: "red" }} dangerouslySetInnerHTML={{__html: message}}/>}
    {status === "success" && <div style={{ color: "green" }}>Subscribed !</div>}
  </div>
)}
/> 

`
but, when I submit the form with email address in this case, the URL of the page gets changed to something like following - http://localhost:3000/?EMAIL=abc%40test.com and the entire page gets refreshed. Also, the email does not get subscribed to the list.

@revolunet
Copy link
Owner

Is it possible for you to create a codesandbox.io example ? will be easier to debug

@jamieweavis
Copy link

You're passing an event directly into the subscribe function @nirajupadhyay11 - when building your own form you need to prevent the default form post and then call subscribe with your own emailAddress variable, like this:

<form
  onSubmit={(event) => {
    event.preventDefault();
    subscribe({ EMAIL: emailAddress });
  }}
>

@roro9999
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants